Reverse Coding Challenge #4 (Code Challenge)

  • Page Owner: Not Set
  • Last Reviewed: 2019-11-15

Reverse Coding Challenge #4

This is a reverse coding challenge. Normally you're given explicit directions with how to create a function. Here, you must generate your own function to satisfy the relationship between the inputs and outputs.

Your task is to create a function that, when fed the inputs below, produce the sample outputs shown.

Examples

"hello" ➞ [4, 1, 3, 3, 1]

"maybe" ➞ [4, 2, 1, 3, 1]

"hopeless" ➞ [0, 7, 0, 5, 4, 5, 3, 3]

"higher" ➞ [2, 3, 1, 2, 5, 0]

"movement" ➞ [5, 7, 6, 5, 5, 5, 6, 4]

Notes

If you get stuck, see Comments for a hint.

Tests

Test = (x, y) => x == y ? console.log("Pass", x, y) || true : console.log("Fail", x, y) || false;

mysteryFunc = x => x;

Test(mysteryFunc("hello"), [4, 1, 3, 3, 1])
Test(mysteryFunc("maybe"), [4, 2, 1, 3, 1])
Test(mysteryFunc("hopeless"), [0, 7, 0, 5, 4, 5, 3, 3])
Test(mysteryFunc("higher"), [2, 3, 1, 2, 5, 0])
Test(mysteryFunc("movement"), [5, 7, 6, 5, 5, 5, 6, 4])

Additional Posts

Here is my (I think) failed attempt. I'm posting it in the hopes that someone smarter than me can figure out why the first two answers I get are wrong:

! letters.split('').map(x => (x.charCodeAt(0) - 96) % letters.length);

The first two test cases fail, with each number in the array being off by one. The rest of the set succeeds. Take a look at my solution and see if it sparks any ideas.

Note: Here are my results. For the FAIL results, the first set is the actual result, the second is the expected result:

   Fail [ 3, 0, 2, 2, 0 ] [ 4, 1, 3, 3, 1 ]
   Fail [ 3, 1, 0, 2, 0 ] [ 4, 2, 1, 3, 1 ]
   Pass
   Pass
   Pass

In the meantime...

Dumb Skinner meme