Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** Javascript code to find odd numbers and remove it withput using loops, filters or naive menthods ***/
- var array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113]; //example array of integers
- function DisplayArray(array1, onpop)
- {
- var value = array1.pop();
- onpop(val); //popping each value in the given array
- if (array1.length > 0) //check the length of the array
- DisplayArray(arr, onpop); //Call the function recursively to access each value in the given array without using loops
- }
- var CollectAray = [];
- DisplayArray(a, function(arrayvalue)
- {
- if (arrayvalue % 2 === 0)
- CollectArray.push(arrayvalue); //push the array value if it is even, thus leaving out odd numbers
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement