文章博客

技术团队文档示例


第九天:数组排排序

<h5>给object数组进行排序(排序条件是每个元素对象的属性个数)</h5> <pre><code>const ObjectArray = [ {a:1,b:2,c:3,d:4}, {a:1,b:2}, {a:2,b:3,c:4} ] // ps 没说升序降序 console.log(ObjectArray.sort((a, b) =&gt; Object.keys(b).length - Object.keys(a).length)); </code></pre> <h5>实现如下语法的功能:var a = (5).plus(3).minus(6); //2</h5> <pre><code>Number.prototype.plus = function(n) { return this + n } Number.prototype.minus = function(n) { return this - n } console.log((5).plus(3).minus(6));</code></pre> <h5>实现如下语法的功能:var a = add(2)(3)(4); //9</h5> <pre><code>const add = (x, i = 0) =&gt; i+1 == 3 ? x : (n) =&gt; add(x+n, i+1) console.log(add(2)(3)(4));</code></pre>

页面列表

ITEM_HTML