Created
March 20, 2018 18:42
-
-
Save cheriimoya/fc23ce59677ece303332fe3437fe43c9 to your computer and use it in GitHub Desktop.
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 keepNumbers(mixedarray){ | |
//create empty array to store the numbers in | |
let numberarray = []; | |
//for each element in the array call the anonymous function... | |
mixedarray.forEach( | |
//... right here | |
function(element) { | |
//check if the element type is "number" | |
if(typeof(element) == "number"){ | |
//if it is, add it to the number array | |
numberarray[numberarray.length] = element; | |
}//otherwise do nothing | |
} | |
); | |
//return the array that just contains numbers | |
return numberarray; | |
} | |
//function is beeing called with a mixed element array | |
keepNumbers(["one", 4, 22, "jdsljf", [2]]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment