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
// Your order, please | |
// https://www.codewars.com/kata/55c45be3b2079eccff00010f | |
/* Solution 1 */ | |
function order(words){ | |
if(!words) { | |
return words; | |
} | |
var arr = words.split(' '); | |
var obj = {}; | |
for(var el of arr) { | |
var number = getNumber(el); | |
obj[number] = el; | |
} | |
return Object.values(obj).join(' '); | |
} | |
function getNumber(str) { | |
return str.match(/\d+/)[0]; | |
} | |
/* Solution 2 */ | |
function order(words) { | |
return words.split(' ').sort((a, b) => getNumber(a) - getNumber(b)).join(' '); | |
} | |
function getNumber(str) { | |
return str.match(/\d/)[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment