JSFiddle - React, Tailwind, and code Playground
JavaScript
function findSolution(target) {
function find(start, history) {
if (start == target)
return history;
else if (start > target) {
console.log(history + ' ← null here')
return null;
}
else {
console.log(history)
return find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
}
}
return find(1, "1");
}
console.log(findSolution(13));