Last active
April 16, 2018 10:44
-
-
Save tamunoibi/c3cca6e36cb7e1f3d8c3de425ed2065a to your computer and use it in GitHub Desktop.
Andela challanges
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 mySort function which takes in an array integers, and should return an array of the inputed integers sorted such that the odd numbers come first and even numbers come last. | |
| For exampl1e: | |
| mySort( [90, 45, 66, 'bye', 100.5] ) | |
| should return | |
| [45, 66, 90, 100] */let mySort = (nums) => { | |
| let sortNums = nums.sort( (a, b) => a - b ); | |
| let filterNums = sortNums.map(num => Math.floor(num)); | |
| let oddNums = []; | |
| let evenNums = []; | |
| for (var i = 0; i < filterNums.length; i++) { | |
| if (filterNums[i] % 2 === 0) { | |
| evenNums.push(filterNums[i]); | |
| } else if (filterNums[i] % 2 > 0) { | |
| oddNums.push(filterNums[i]); | |
| } | |
| }; | |
| let newNums = oddNums.concat(evenNums); | |
| return newNums; | |
| }; | |
| mySort([90, 45, 66, 'bye', 100.5]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment