Created
April 12, 2017 05:29
-
-
Save anonymous/50a1576af45dd91815919c7b174b7eee to your computer and use it in GitHub Desktop.
5.2 Even and Odd created by smillaraaq - https://repl.it/HERy/2
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
| function evenOdd(myArray){ | |
| var oddArray=[]; | |
| var evenArray=[]; | |
| var combinedArray=[]; | |
| for(var i=0;i<myArray.length;i++){ | |
| if(!(i%2)){ | |
| evenArray.push(myArray[i]); | |
| }else{ | |
| oddArray.push(myArray[i]); | |
| } | |
| } | |
| combinedArray.push(oddArray, evenArray); | |
| return combinedArray; | |
| } | |
| var outputArray = evenOdd([1,2,3,4,5,6]); | |
| console.log(myArray) | |
| function evenOdd(myArray){ | |
| var oddArray=[]; | |
| var evenArray=[]; | |
| var combinedArray=[]; | |
| for(var i=0;i<myArray.length;i++){ | |
| if(!(myArray[i]%2)){ | |
| evenArray.splice(evenArray.length,0,myArray[i]); | |
| }else{ | |
| oddArray.splice(oddArray.length,0,myArray[i]); | |
| } | |
| } | |
| combinedArray.splice(0,0,oddArray, evenArray); | |
| return combinedArray; | |
| } | |
| console.log(evenOdd([323,12,1,4,23,42])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment