Created
May 16, 2018 16:08
-
-
Save fhereduardo90/4bcd657aaf52beb040171731f28a8ee6 to your computer and use it in GitHub Desktop.
Sorting Numbers
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
const numbers = ['1.2.3', '10.5.6', '6.3.4', '10.6.7', '10.5.5']; | |
console.log(`unsorted numbers => ${numbers.join(', ')}`); | |
numbers.sort((prev, nxt) => { | |
const [a, b, c] = prev.split('.').map(Number); | |
const [x, y, z] = nxt.split('.').map(Number); | |
return a > x || b > y || c > z; | |
}); | |
console.log(`sorted numbers => ${numbers.join(', ')}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment