Skip to content

Commit

Permalink
Implements COunt value in array
Browse files Browse the repository at this point in the history
  • Loading branch information
kleekich committed Sep 4, 2018
1 parent 9bf8f37 commit c832e07
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/recursion.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ var fizzBuzz = function(n) {
// countOccurrence([2,7,4,4,1,4], 4) // 3
// countOccurrence([2,'banana',4,4,1,'banana'], 'banana') // 2
var countOccurrence = function(array, value) {
if(array.length === 0) return 0;
return array[0] === value ? 1 + countOccurrence(array.slice(1), value) : countOccurrence(array.slice(1), value);
};

// 21. Write a recursive version of map.
Expand Down

0 comments on commit c832e07

Please sign in to comment.