Would you please add a test case.
See original GitHub issueChallenge 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:
- Created 7 years ago
- Comments:12 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
@brianhankins please go ahead and make pull request if you are ready. Thanks.