Skip to content

Instantly share code, notes, and snippets.

@nickbclifford
Last active February 18, 2017 17:34
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 nickbclifford/3cc91a26ee10b4b8345cb167faba88ae to your computer and use it in GitHub Desktop.
Save nickbclifford/3cc91a26ee10b4b8345cb167faba88ae to your computer and use it in GitHub Desktop.
Domino's Pizza JavaScript challenge
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