Skip to content

Instantly share code, notes, and snippets.

@wavesoft
Created December 31, 2020 17:14
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 wavesoft/f3f232baaec119e6be329b521111fb29 to your computer and use it in GitHub Desktop.
Save wavesoft/f3f232baaec119e6be329b521111fb29 to your computer and use it in GitHub Desktop.
Javascript Quiz

The following javascript function contains 3 errors. Can you spot them?

((b, d = " .@ABDEIJMNORTUV") => {
  const keys = { one: {}, two: {} };
  const codepoints = Array.from(b).forEach((v) => v.codePointAt(0));
  const decode = (number, v = number - b.codePointAt(0)) => ({
    [keys.one]: d[v >> 4],
    [keys.two]: d[v & 15],
  });
  // Decode the secret message
  let message = "";
  for (let i = 1; i < codepoints.length; ++i) {
    var emoji = codepoints[i];
    setTimeout(() => {
      const { [keys.one]: a, [keys.two]: b } = decode(emoji);
      message += a + b;
    }, i);
  }
  // And show it :)
  setTimeout(() => {
    console.log(message);
  }, b.length);
})("πŸ€πŸ“†πŸ‘ΊπŸ“ΆπŸ’­πŸƒπŸ“­πŸ’ΉπŸ½πŸ‘»πŸ’‘πŸˆπŸ’·πŸ’’πŸ‘ƒπŸ“…πŸ‘¦πŸ’‘πŸ·");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment