Created
January 27, 2020 18:49
-
-
Save LautaroJayat/700d00b8c7ccf8ba0bc562ed879caafb to your computer and use it in GitHub Desktop.
Array Question
This file contains 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
let array = [1, 2, 3, '4', undefined, 'a', [], null]; | |
function onlyNumbers(arr) { | |
let output = []; | |
// If 'isNaN()' doesn't return true for the given element, we pushit to the output array | |
arr.forEach(e => { if (!isNaN((e))) { output.push((e)) } }) | |
return output | |
} | |
console.log(onlyNumbers(array)); | |
// Wich outputs [ 1, 2, 3, '4', [], null]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment