Last active
February 18, 2017 17:34
-
-
Save nickbclifford/3cc91a26ee10b4b8345cb167faba88ae to your computer and use it in GitHub Desktop.
Domino's Pizza JavaScript challenge
This file contains 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 say(firstStr) { | |
// gotta love currying! | |
return function(secondStr) { | |
function hyphenSeparate(str) { | |
return str.replace(/[.,'"?!]/g, '') // remove punctuation | |
.split('') // split into array of chars | |
.reduce((a, v) => a + '-' + v); // concatenate with hyphens in between | |
} | |
return hyphenSeparate(firstStr) + ' ' + hyphenSeparate(secondStr); | |
} | |
} | |
console.log(say('Domino\'s')('Pizza') === 'D-o-m-i-n-o-s P-i-z-z-a'); | |
console.log(say('Front')('End!') === 'F-r-o-n-t E-n-d'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment