Created
September 4, 2019 00:12
-
-
Save dasider41/cd12966d607aee28b2ee3db0cec1a652 to your computer and use it in GitHub Desktop.
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
const arr = [ | |
"apple", | |
[ | |
"banana", | |
"strawberry", | |
"apple", | |
["banana", "strawberry", "apple", ["banana", "strawberry", "apple"]] | |
] | |
]; | |
const countItems = (arr, item) => | |
arr.flat(Infinity).filter(val => val === item).length; | |
console.log(countItems(arr, "apple") === 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment