Last active
December 27, 2015 19:14
-
-
Save mmloveaa/3f1706b2cdcb9df27528 to your computer and use it in GitHub Desktop.
We Have Liftoff
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
// 12/22/2015 | |
// You have an array of numbers 1 through 10 (JS: 1 through 10 or less). The array needs to be formatted correctly for the person | |
reading the countdown of a spaceship launch. | |
// Unfortunately, the person reading the countdown only knows how to read strings. After the array is sorted correctly make | |
sure it's in a format he can understand. | |
// Between each number should be a space and after the final number (1) should be the word 'liftoff!' | |
// Example: | |
// Given | |
// instructions = [8,1,10,2,7,9,6,3,4,5] | |
// Should return | |
// "10 9 8 7 6 5 4 3 2 1 liftoff!" | |
// Given | |
// instructions = [1,2,4,3,5] | |
// Should return | |
// "5 4 3 2 1 liftoff!" | |
// My Solution: | |
function liftoff(arr){ | |
arr=arr.sort(function(a,b){ | |
return b-a; | |
}) | |
var str="" | |
str=arr.join(" ")+" liftoff!" | |
return str | |
} | |
//Refactoring code | |
function liftoff(arr){ | |
return arr.sort(function(a,b){ | |
return b-a; | |
}).join(" ") + " Liftoff!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment