# 《Eloquent JavaScript》读后感

Last Updated:## 2022-08-12

# 简介

## ECMAScript 历史(es3->es5->es6...)

There have been several versions of JavaScript. ECMAScript version 3 was the widely supported version in the time of JavaScript’s ascent to dominance, roughly between 2000 and 2010

basically no version 4(2008), comes version 5(2009)

es6(ECMAScript version 6 came out in 2015, is a major update)

work on the version 4 was abandoned in 2008, leading to a much less ambitious version 5, which made only some uncontroversial improvements, coming out in 2009. Then in 2015 version 6 came out, a major update that included some of the ideas planned for version 4. Since then we’ve had new, small updates every year.

# 第三章，函数

## 递归函数，求结果（感觉就像二叉树遍历)

^33c96f

问题描述:

Consider this puzzle: by starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite set of numbers can be produced. How would you write a function that, given a number, tries to find a sequence of such additions and multiplications that produces that number?

答案:

```
function findSolution(target) {
function find(current, history) {
if (current == target) {
return history;
} else if (current > target) {
return null;
} else {
return find(current + 5, `(${history} + 5)`) ||
find(current * 3, `(${history} * 3)`);
}
}
return find(1, "1");
}
console.log(findSolution(24));
// → (((1 * 3) + 5) * 3)
```

上述答案，不求最优解，但求有解