Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created November 24, 2017 08:54
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 alextanhongpin/f8769271ed3a57452d760bf6e5a62fbb to your computer and use it in GitHub Desktop.
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…
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