Created
February 22, 2018 15:58
-
-
Save mansouryaacoubi/091c4582623faf300931b15da5953319 to your computer and use it in GitHub Desktop.
Find amount of occurrences of value in array (Javascript)
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
Array.prototype.occurrences = function(val) { | |
var i = 0, c = 0; | |
while( (i = this.indexOf(val,i)+1) && ++c ); | |
return c; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment