Skip to content

Instantly share code, notes, and snippets.

@colevandersWands
Last active November 4, 2021 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colevandersWands/6564fa0cde76cefef1cfeea9426290ee to your computer and use it in GitHub Desktop.
Save colevandersWands/6564fa0cde76cefef1cfeea9426290ee to your computer and use it in GitHub Desktop.
testing code tags in a summary

#todo

Mirrorize

Which line can be placed in the blank to make a loop that mirrors the input? There may be more than 1 correct answer!

'use strict';

let text = 'abc';

let mirrored = '|';
for (let char of text) {
  __;
}

console.log(mirrored); // 'cba|abc'

A: let mirrored = char + mirrored;

✖ Nope.

Close! This is line contains one half of the correct solution.

This is how you reverse a string. The characters from "abc" will be added in order to the front of the mirrored string. The final log will be:

  • "cba|"

B: mirrored = mirrored + char;

✖ Nope.

Close! This is line contains one half of the correct solution.

This line of code will just rebuild the original text one character at a time, adding each one to the end of the growing string. The final log will be:

  • "|abc"

C: mirrored = char + mirrored + char;

✔ Correct!

With each iteration, this line of code will add the same character to both end of the mirrored string. The final result will be a string with the reversed text on the left, and the original text on the right:

  • "cba|abc"

D: mirrored = mirrored + char + mirrored;

✖ Nope.

Much cooler, but not correct. Can you figure out why the final log looks like this?

  • "|a|b|a|c|a|b|a|"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment