Created
July 11, 2018 14:48
-
-
Save ravivit9/6e5b2f10d8dd89453739e5fa01308acf to your computer and use it in GitHub Desktop.
Search for a string value from an array of items and return those matching array items.
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
var dataset = [2,2,4,2,6,4,7,8]; | |
var search = 2; | |
var count = dataset.reduce(function(n, val) { | |
return n + (val === search); | |
}, 0); | |
console.log(count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment