Skip to content

Instantly share code, notes, and snippets.

@rproenza86
Created January 4, 2017 20:33
Show Gist options
  • Save rproenza86/de16eea752860fc9544bbcec8d6f8fbc to your computer and use it in GitHub Desktop.
Save rproenza86/de16eea752860fc9544bbcec8d6f8fbc to your computer and use it in GitHub Desktop.
/**
Code Challenge Needed:
Using Javascript, given an array of n integers (example: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113] ), remove all odd numbers, leaving only the even numbers.
Rules:
NO LOOPING. This means native methods, or libraries that loop for you are not allowed either.
Supply the answer on github via Gist
**/
var numbersArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113];
//initial array
window.prompt('The original numbers array was : ', numbersArray);
//final array output (I think this is not a good practice talking about maintenance and readability of code, this is just a creative solution using regular expresions and string manipulation)
window.prompt( 'The evens numbers are 1: ', numbersArray.join().match(/\w?(\d+)*[24680]/g) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment