question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Would you please add a test case.

See original GitHub issue

Challenge Search and Replace has an issue. User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

Would you please add the following test case? myReplace(“His name is KING”, “KING”, “Tom”) should return “His name is TOM”

My code:


function myReplace(str, before, after) {
    var wordArray = str.split(' ');
    
    for (var i = 0; i < wordArray.length; i++) {
      if (wordArray[i] === before) {
        // get case list
        // ArraY shoud be [true, false, false, false, true]
        var caseList = []; 
        for (var j = 0; j < wordArray[i].length; j++) {
          if (wordArray[i].charAt(j) == wordArray[i].charAt(j).toUpperCase()) {
            caseList.push(true);
          } else {
            caseList.push(false);
          }
        }
        
//         console.log(caseList + before.length);
        
        var afterWithCase = "";
        for (var k = 0; k < after.length; k ++) {
          if (k >= caseList.length) {
            afterWithCase = afterWithCase + after.charAt(k);
            continue;
          }
          if (caseList[k]) {
            afterWithCase = afterWithCase + after.charAt(k).toUpperCase();
//             console.log("false;" + after.charAt(k).toUpperCase());
          } else {
            afterWithCase = afterWithCase + after.charAt(k).toLowerCase();
//             console.log("false;" + after.charAt(k).toLowerCase());
          }
        }
        
        wordArray[i] = afterWithCase;

      }  
    }

    return wordArray.join(" ");
}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
raisedadeadcommented, Dec 12, 2016

@ajain17 Well most of us do… 😉 ! or we will make sure someone does repond. Hit us up in the chat for anything (that needs a chat/discussion). Most mods follow that.

And yup please go ahead with the PR when you are ready! Make sure you address @systimotic 's https://github.com/FreeCodeCamp/FreeCodeCamp/issues/11862#issuecomment-264212993 above.

2reactions
raisedadeadcommented, Dec 30, 2016

@brianhankins please go ahead and make pull request if you are ready. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Write Test Cases in Software Testing with Examples
For documenting Test Cases: With tools, you can expedite Test Case creation with use of templates · Execute the Test Case and Record...
Read more >
How to Write Test Cases: The Ultimate Guide with Examples
As a tester, whenever you are asked to write test documentation, do not just start away in an ad hoc manner. It is...
Read more >
How to Write Test Cases for Software: Examples & Tutorial
But functional testing is just one aspect of writing a test case. Software testing should robustly challenge every aspect of the code from ......
Read more >
Adding Test Cases to Coding Questions
You can add the required number of sample test cases to a question and choose not to assign scores for them.
Read more >
Add a new test case to a test plan
Add new test cases to your test plans so that you can assign them to testers and start test execution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found