还不是爱你 2022-05-04 13:55:01
(一)var a = 1000100100 = 100 + 1001000 + 100100010000;
(二)var b = 1010010000 = 10000+100001000+100001000100;
a<b
但大头100001000100不变
还不是爱你 2022-05-04 13:54:12
感觉题目可以清晰一些,指定retry的入参是啥
Promise.retry = function (fn, times) { return new Promise((rs, rj) => { return fn().then((res) => { rs(res) }).catch((err) => { if (--times >= 0) { return Promise.retry(fn, times) } else { rj(err) } }) }) }
我就想问这一句:return fn().then((res) => rs(res));
题目没说fn函数返回的一定是Promise吧?普通函数调用then不就报错了
还不是爱你 2022-05-04 13:53:56
function deepClone(obj, hash = new WeakMap()) { if (hash.has(obj)) return obj; var cobj; // null if (obj === null) { return obj } let t = typeof obj; // 基本类型 switch (t) { case 'string': case 'number': case 'boolean': case 'undefined': return obj; } // 数组 if (Array.isArray(obj)) { cobj = []; obj.forEach((c, i) => { cobj.push(deepClone(obj[i])) }); } else { cobj = {}; // object // symbol if (Object.prototype.toString.call(obj) === "[object Object]") { Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj)).forEach(c => { hash.set(obj, obj); cobj[c] = deepClone(obj[c], hash); }); } else { //内置Object cobj = obj; } } return cobj; }
var a=[];
a.push(a);
deepClone(a);
- 共 1 页
- 1
sort(): [102, 15, 22, 29, 3, 8]
sort((a,b)=> a-b): [3, 8, 15, 22, 29, 102]
第 43 题:使用 sort() 对数组 [3, 15, 8, 29, 102, 22] 进行排序,输出结果