Advertisement
Guest User

Untitled

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