Skip to content

Instantly share code, notes, and snippets.

@kutyel
Last active June 30, 2017 10:22
Show Gist options
  • Save kutyel/ead4eb84ca91859e947bca37f1a78ba5 to your computer and use it in GitHub Desktop.
Save kutyel/ead4eb84ca91859e947bca37f1a78ba5 to your computer and use it in GitHub Desktop.
Translate to badger language using native JavaScript functional programming (without Ramda.js)
/**
* Translate a sentence to badger language,
* applying the following transformations:
*
* 1) Reverse letters
* 2) Capitalize first letter
* 3) Reverse words
*
* Sample input: "Thank you"
* Sample output: "Uoy Knaht"
*
*/
const reverse = x => x
.split('')
.reverse()
.join('')
const capitalizeFirstLetter = x => x
.charAt(0)
.toUpperCase()
.concat(x.slice(1))
const translateToBadger = words => words
.split(' ')
.reverse()
.map(reverse)
.map(capitalizeFirstLetter)
.join(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment