Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. function functionalFib(numOfElements) {
  2. function fib(a) {
  3. if (a === 0) {
  4. return 0;
  5. }
  6. if (a === 1) {
  7. return 1;
  8. }
  9. return fib(a - 1) + fib(a - 2);
  10. }
  11.  
  12. function repeat(num, max, arr) {
  13. if (num > max) {
  14. return arr;
  15. }
  16. return repeat(num + 1, max, [].concat(arr, fib(num)))
  17. }
  18. return repeat(1, numOfElements, []);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement