Files
Nicholas Carrigan (he/him) 7117919d36 chore(learn): audit javascript algorithms and data structures (#41092)
* chore(learn): audit basic algorithm scripting

* chore(learn): audit basic data structures

* chore(learn): audit basic javascript

* chore(learn): audit debugging

* chore(learn): audit es6

* chore(learn): audit functional programming

* chore(learn): audit intermidate algorithms

* chore(learn): audit js projects

* chore(learn): audit object oriented programming

* chore(learn): audit regex

* fix(learn): remove stray .

* fix(learn): string to code

* fix(learn): missed some

* fix(learn): clarify strings

Based on Randy's feedback, clarifies string instances where quotes
were removed in favour of back ticks.

* fix: apply suggestions - thanks Randy! :)

Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* fix: non-suggestion comments

* chore(learn): remove comments from codes

Removes the comments from the description and instruction code
blocks to ensure that all relevant information is translatable.

* fix: Apply suggestions from code review

Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

* fix: revert crowdin fix

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md

Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* fix: Apply suggestions from code review

Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md

Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

* fix: Apply suggestions from code review

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

* chore: change voice

* fix: Christopher Nolan

* fix: expressions would evaluate

* fix: will -> would

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md

Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* fix: to work to push

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md

Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md

Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-03-02 17:12:12 -07:00

2.6 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a0b5010f579e69b815e7c5d6 Search and Replace 5 16045 search-and-replace

--description--

Perform a search and replace on the sentence using the arguments provided and return the new sentence.

First argument is the sentence to perform the search and replace on.

Second argument is the word that you will be replacing (before).

Third argument is what you will be replacing the second argument with (after).

Note: Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word Book with the word dog, it should be replaced as Dog

--hints--

myReplace("Let us go to the store", "store", "mall") should return the string Let us go to the mall.

assert.deepEqual(
  myReplace('Let us go to the store', 'store', 'mall'),
  'Let us go to the mall'
);

myReplace("He is Sleeping on the couch", "Sleeping", "sitting") should return the string He is Sitting on the couch.

assert.deepEqual(
  myReplace('He is Sleeping on the couch', 'Sleeping', 'sitting'),
  'He is Sitting on the couch'
);

myReplace("I think we should look up there", "up", "Down") should return the string I think we should look down there.

assert.deepEqual(
  myReplace('I think we should look up there', 'up', 'Down'),
  'I think we should look down there'
);

myReplace("This has a spellngi error", "spellngi", "spelling") should return the string This has a spelling error.

assert.deepEqual(
  myReplace('This has a spellngi error', 'spellngi', 'spelling'),
  'This has a spelling error'
);

myReplace("His name is Tom", "Tom", "john") should return the string His name is John.

assert.deepEqual(
  myReplace('His name is Tom', 'Tom', 'john'),
  'His name is John'
);

myReplace("Let us get back to more Coding", "Coding", "algorithms") should return the string Let us get back to more Algorithms.

assert.deepEqual(
  myReplace('Let us get back to more Coding', 'Coding', 'algorithms'),
  'Let us get back to more Algorithms'
);

--seed--

--seed-contents--

function myReplace(str, before, after) {
  return str;
}

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

--solutions--

function myReplace(str, before, after) {
  if (before.charAt(0) === before.charAt(0).toUpperCase()) {
    after = after.charAt(0).toUpperCase() + after.substring(1);
  } else {
    after = after.charAt(0).toLowerCase() + after.substring(1);
  }
  return str.replace(before, after);
}