Created
January 31, 2022 16:14
-
-
Save jcolebot/5cdb18d6ebfd7a222355e99dd767a71f to your computer and use it in GitHub Desktop.
Filter Out Strings from an Array
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
| // Filter Out Strings from an Array | |
| // Create a function that takes an array of non-negative integers and strings and returns a new array without the strings. | |
| // Examples | |
| // filterArray([1, 2, "a", "b"]) ➞ [1, 2] | |
| // filterArray([1, "a", "b", 0, 15]) ➞ [1, 0, 15] | |
| // filterArray([1, 2, "aasf", "1", "123", 123]) ➞ [1, 2, 123] | |
| // Notes | |
| // Zero is a non-negative integer. | |
| // The given array only has integers and strings. | |
| // Numbers in the array should not repeat. | |
| // The original order must be maintained. | |
| function filterArray(arr) { | |
| return arr.filter(element => typeof element !== 'string'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment