Skip to content

Commit

Permalink
Implement Recursive Map
Browse files Browse the repository at this point in the history
  • Loading branch information
kleekich committed Sep 4, 2018
1 parent c832e07 commit f0bab53
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 @@ -198,6 +198,8 @@ var countOccurrence = function(array, value) {
// 21. Write a recursive version of map.
// rMap([1,2,3], timesTwo); // [2,4,6]
var rMap = function(array, callback) {
if(array.length === 0) return [];
return [callback(array[0])].concat(rMap(array.slice(1),callback));
};

// 22. Write a function that counts the number of times a key occurs in an object.
Expand Down

0 comments on commit f0bab53

Please sign in to comment.