Created
May 12, 2016 23:15
-
-
Save faruzzy/ed6e2a19e62957537d5dcd8aea8504bc to your computer and use it in GitHub Desktop.
Problem 4 from https://www.shiftedup.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
This file contains hidden or 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
// write a function that given a list of non negative integers, arranges them | |
// such that they form the largest possible number. | |
// [50, 2, 1, 9] -> 95021 | |
function arrange(array) { | |
array.sort(function(a, b) { | |
return String(a) < String(b); | |
}); | |
return parseInt(array.join('')); | |
} | |
var array = [50, 2, 1, 9, 55]; | |
console.log(arrange(array)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment