Guest User

Recursion

a guest
Sep 7th, 2015
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function findSolution(target) {
  2.  
  3.     function find(start , history) {
  4.  
  5.     if (start == target) return history;
  6.  
  7.     else if (start > target) return null;
  8.  
  9.     else return find(start + 5, "(" + history + " + 5)") || find(start * 3, "(" + history + " * 3)");
  10.  
  11. }
  12.  
  13.  
  14. return find(1, "1");
  15.  
  16. }
  17.  
  18. console.log(findSolution(24));
RAW Paste Data