Created
November 24, 2017 08:54
-
-
Save alextanhongpin/f8769271ed3a57452d760bf6e5a62fbb to your computer and use it in GitHub Desktop.
The question is as follow, for each word in the line, print the character based on the index if the length is greater than the index [4:52] so for the first line, `[h]ey g[o]od la[w]yer` (edited) [4:53] hey is the first word, so take the first index, which is `h` good is the second word, so take the second index, which is `o`... [4:53] if the se…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function decrypt (str) { | |
let counter = 0 | |
return str.split(' ').reduce((a, b) => { | |
if (b.length >= counter + 1) { | |
const part = b[counter] | |
counter += 1 | |
return a + part | |
} | |
return a | |
}, '') | |
} | |
function main () { | |
const inputs = [ | |
'hey good lawyer', | |
'as I previously previewed', | |
'yam does a soup', | |
'first I give money to teresa', | |
'after I inform dad of', | |
'your horrible soup' | |
] | |
console.log(inputs.map(decrypt)) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment