1.ES6 array traversal syntax sugar =
It was used in c#linq, so it's not very strange.
var range = array.apply (null, Array (x)). Map ((_, i) = = ++i);
A method for filling an empty array with apply is applied.
Apply applies to arrays as well: passing an array to a function that does not accept an array as a parameter, flattening a two-dimensional array (e.g.). The function parameter has an array.
> Math.max.apply (null, [1, 5])10
2. Use recursion to calculate the sum of squares:
function cal (x) { return x==1?1: (Cal (x-1) +x*x);}
>cal (10)
When x is 1000, the stack overflow is prompted.
Then use tail recursion:
function cal (x, y ) {return x==0?1: (Cal (x-1,x*x) +y); } >cal (10,0)385
Codewars Backstage no error. However, after reading a number of articles (e.g.http://bbs.csdn.net/topics/390317532) found that the tail recursion still can not escape stackoverflow problem. Actually tested, the above two function cal (30000) will give an error.
3. Sparse arrays
[,,].every (function(x) {return x==22222})true
A sparse array skips "empty elements" as it traverses. I haven't thought of a way yet.
The array of JS is actually a key-value pair of strings and values. Just a special object.
Codewars with Notes