-
-
Save SirPhemmiey/c90a9ce522046611ca7cd1d1d8f4b27b to your computer and use it in GitHub Desktop.
Revisions
-
Samuelachema created this gist
Aug 14, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ /* JavaScript 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] */ function mySort(nums) { let evens = []; let odds = []; for (let i = 0; i < nums.length; i++) { if(typeof nums[i] === "number"){ // ignore if its not a number if ((nums[i] % 2) === 1) { odds.push(parseInt(nums[i])); } else { evens.push(parseInt(nums[i])); } } } let numsArray = odds.sort((a, b) => a - b).concat(evens.sort((a, b) => a - b)); return numsArray; }