Get number of Occurrences - Node.js Number

Node.js examples for Number:Algorithm

Description

Get number of Occurrences

Demo Code


// http://www.codewars.com/kata/52829c5fe08baf7edc00122b/train/javascript

Array.prototype.numberOfOccurrences = function(number) {
  return this.reduce(function (previous, current) {
    return (current === number) ? ++previous : previous;
  }, 0);/* ww w .j  a va  2  s. c o m*/
};

Related Tutorials