# Sum 100
Cho chuỗi "123456789", chèn '+', '-' vào giữa chuỗi đó để ra được kết quả 100
const recursiveFn = (remainNumberList, remainSum = 100, builtStr) => {
const completed = !remainNumberList && remainSum === 0;
if (completed && !builtStr.startsWith('*') && !builtStr.startsWith('/') ) {
console.log(`${builtStr} = ${eval(builtStr)}`);
return;
}
const len = remainNumberList.length;
for(let i = 1; i <= len; i++) {
const prefix = remainNumberList.substr(0, i);
const postfix = remainNumberList.substr(i, len);
const number = parseInt(prefix);
recursiveFn(postfix, remainSum - number, builtStr + '+' + number);
recursiveFn(postfix, remainSum + number, builtStr + '-' + number);
}
}
recursiveFn('123456789', 100, '');