Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Added answers for addional recursion problems #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/recursion.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ define(function() {
temp.slice()
);
}
},

fibonacci: function fib(n) {
if (n < 2) {
return n;
}
return fib(n - 1) + fib(n - 2);
},

validParentheses: function(n) {
var sets = [];
var getParen = function(left, right, current) {
if (left == 0 && right == 0) {
sets.push(current);
}
if (left > 0) {
getParen(left - 1, right + 1, current + '(');
}
if (right > 0) {
getParen(left, right - 1, current + ')');
}
return sets;
};
return getParen(n, 0, '');
}
};
});
Expand Down