Skip to content

Instantly share code, notes, and snippets.

@ian-bartholomew
Last active January 5, 2017 00:47
Show Gist options
  • Save ian-bartholomew/9e973ddfa0d3425229f642f78306cc3f to your computer and use it in GitHub Desktop.
Save ian-bartholomew/9e973ddfa0d3425229f642f78306cc3f to your computer and use it in GitHub Desktop.
Codewars JS
function order(words){
// return empty string for undefined
if (words === undefined) {
return '';
}
let rval = [];
let pieces = words.split(' ');
for (let i=0; i<10; i++) {
if (pieces.hasOwnProperty(i)) {
let piece = pieces[i].match(/\d/);
if (piece) {
rval[piece[0]] = piece.input;
}
}
}
return rval.join(' ').trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment