Skip to content

Instantly share code, notes, and snippets.

@faruzzy
Created May 12, 2016 23:15
Show Gist options
  • Save faruzzy/ed6e2a19e62957537d5dcd8aea8504bc to your computer and use it in GitHub Desktop.
Save faruzzy/ed6e2a19e62957537d5dcd8aea8504bc to your computer and use it in GitHub Desktop.
// 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