function findSolution target function find current history if current

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
function findSolution (target){
function find(current,history){
if (current == target){
return history;
}
else if (target < current){
return null;
}
else{
return find(current + 5, `(${history} + 5)`) || find(current * 3,`(${history} * 3)`);
}
}
return find(1,"1");
}
console.log(findSolution(24));
// => (((1 * З) + 5) * З)