Last active
April 2, 2017 04:29
-
-
Save vacas/ed0a7ab70b49285a5614a03e14baeb3e to your computer and use it in GitHub Desktop.
Coding Challenge for Codetrotters Fellowship - Goal: Function that takes an array of whole numbers and organizes them in the largest possible number together
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
var arrays = [ | |
[9, 17, 0, 50], | |
[ 342, 689 ], | |
[ 43, 5, 12, 99 ], | |
[ 8, 4, 100 ], | |
[ 0, 1, 2, 3, 4, 5, 6, 7 ] | |
]; | |
function createHighestNumber(input, firstDigit, output){ | |
while (input.length > 0) { | |
for (var j = 0; j < firstDigit.length; j++) { | |
if (firstDigit[j] == Math.max.apply(null, firstDigit)) { | |
output += input[j].toString(); | |
input.splice(j, 1); | |
firstDigit.splice(j, 1); | |
} | |
} | |
} | |
return output; | |
} | |
function highestNumber(array) { | |
var list = [], | |
str = ''; | |
for (var i = 0, end = array.length; i < end; i++) { | |
list.push(array[i].toString()[0]); | |
} | |
str = createHighestNumber(array, list, str); | |
return str; | |
} | |
for (var n = 0; n < arrays.length; n++) { | |
highestNumber(arrays[n]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment