网站建设合同用贴印花税吗,制作灯笼的手工做法步骤,公司网站的宣传栏怎么做,微信转wordpress常考算法 排序算法#xff1a;快速排序、归并排序、堆排序等。 查找算法#xff1a;二分查找、哈希表查找等。 动态规划#xff1a;解决最优化问题#xff0c;如斐波那契数列、最长公共子序列等。 图论算法#xff1a;最短路径#xff08;Dijkstra、Floyd-Warshall快速排序、归并排序、堆排序等。 查找算法二分查找、哈希表查找等。 动态规划解决最优化问题如斐波那契数列、最长公共子序列等。 图论算法最短路径Dijkstra、Floyd-Warshall、拓扑排序等。 字符串处理KMP算法、正则表达式匹配等。
遍历方法总结 链式调用
数组的很多操作可以构成链式操作类似这样的格式…map().filter(…).sort(…).map(….)链式操作就是对象方法返回类型是自身的。比如map是属于数组的方法它返回数组所以构成了链式操作优势语义清晰、思考方便数据量小的时候很有用(1W)问题性能、空间
递归
递归通常需要初始条件和递归表达式
阶乘n! n x (n-1) !
斐波那契f(1) 1, f(2) 1f(n) f(n-1) f(n-2), n2 拷贝
push/pop/shift/unshift/splice都在原始数据上进行修改
concat/slice/map/reduce都会对原始数据进行浅拷贝 DOM结点的绝对位置
offsetLeft、offsetRight相对于offsetParent的位置 Element.getBoundingClientRect()相对于视窗的位置受滚动的影响 !DOCTYPE html
html langen
headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0title递归/title
/head
bodyscript// 阶乘function factorial(n) {if (n 1) return 1return n * factorial(n - 1)}// 斐波那契数列 1 1 2 3 5 8 13 21 34 55 89 144function fibonacci(n) {if (n 1 || n 2) return 1return fibonacci(n - 1) fibonacci(n - 2)}// 从底端构造递归function fibonacci1(n) {let [a,b] [1,1]for(let i 3; i n; i) {[a,b] [b, a b]}return b}// console.log(测试 fibonacci1);// console.log(fibonacci1(10));function fibonacci2(n) {return Array(n - 2).fill(0).reduce(([a,b],_) {return [b, a b]}, [1,1])[1]}// console.log(测试 fibonacci2);// console.log(fibonacci2(10));// 递归实现深拷贝function deepClone(obj) {if (typeof obj ! object || obj null) return obj// const newObj Array.isArray(obj) ? [] : {}// const newObj obj instanceof Array ? [] : {}// const newObj obj.constructor Array ? [] : {}// const newObj Object.prototype.toString.call([]) [object Array] ? [] : {}const newObj new obj.constructor()for(let key in obj) {if(obj.hasOwnProperty(key)) {newObj[key] deepClone(obj[key])}}return newObj}// 测试用例 function testDeepClone() { console.log(测试普通对象:); const obj1 { a: 1, b: { c: 2 } }; const clonedObj1 deepClone(obj1); console.assert(obj1 ! clonedObj1, 对象应该是不同的引用); console.assert(obj1.b ! clonedObj1.b, 嵌套对象也应该是不同的引用); console.assert(obj1.b.c clonedObj1.b.c, 嵌套对象的属性值应该相等); console.log(测试数组:); const arr1 [1, 2, [3, 4]]; const clonedArr1 deepClone(arr1); console.assert(arr1 ! clonedArr1, 数组应该是不同的引用); console.assert(arr1[2] ! clonedArr1[2], 嵌套数组也应该是不同的引用); console.assert(arr1[2][0] clonedArr1[2][0], 嵌套数组的元素值应该相等); console.log(测试特殊对象Date:); const date1 new Date(); const clonedDate1 deepClone(date1); console.assert(date1 ! clonedDate1, Date 对象应该是不同的引用); console.assert(date1.getTime() clonedDate1.getTime(), Date 的时间戳应该相等); // console.log(测试特殊对象RegExp:); // 失败 // const reg1 /hello/g; // const clonedReg1 deepClone(reg1); // console.assert(reg1 ! clonedReg1, RegExp 对象应该是不同的引用); // console.assert(reg1.source clonedReg1.source reg1.global clonedReg1.global, RegExp 的属性和标志应该相等); // console.log(测试循环引用:); // 失败 // const obj2 {}; // obj2.self obj2; // const clonedObj2 deepClone(obj2); // console.assert(obj2 ! clonedObj2, 对象应该是不同的引用); // console.assert(clonedObj2.self clonedObj2, 循环引用应该被正确处理); console.log(所有测试通过); } // testDeepClone();// 深度比较function deepCompare(a,b){if (a null || typeof a ! object || b null || typeof b ! object) {return a b}// Object.getOwnPropertyDescriptors 方法会返回对象自身的所有属性描述符包括不可枚举的属性const propsA Object.getOwnPropertyDescriptors(a)const propsB Object.getOwnPropertyDescriptors(b)if(Object.keys(propsA).length ! Object.keys(propsB).length) return falsereturn Object.keys(propsA).every(key deepCompare(a[key],b[key]))}// 测试用例 function testDeepCompare() { console.log(测试基本相等性:); console.assert(deepCompare(1, 1), 1 应该等于 1); console.assert(!deepCompare(1, 2), 1 不应该等于 2); console.assert(deepCompare(null, null), null 应该等于 null); console.assert(deepCompare(undefined, undefined), undefined 应该等于 undefined); console.assert(!deepCompare(null, undefined), null 不应该等于 undefined); console.log(测试对象比较:); const obj1 { a: 1, b: { c: 2 } }; const obj2 { a: 1, b: { c: 2 } }; const obj3 { a: 1, b: { c: 3 } }; console.assert(deepCompare(obj1, obj2), obj1 应该等于 obj2); console.assert(!deepCompare(obj1, obj3), obj1 不应该等于 obj3); console.log(测试数组比较:); const arr1 [1, 2, [3, 4]]; const arr2 [1, 2, [3, 4]]; const arr3 [1, 2, [3, 5]]; console.assert(deepCompare(arr1, arr2), arr1 应该等于 arr2); console.assert(!deepCompare(arr1, arr3), arr1 不应该等于 arr3); // console.log(测试循环引用此实现可能无法正确处理:); // const obj4 {}; // obj4.self obj4; // const obj5 {}; // obj5.self obj5; // 注意此实现可能无法正确处理循环引用因为它会陷入无限递归 // 这里我们假设它不会处理循环引用并跳过这个测试 // console.assert(deepCompare(obj4, obj5), 循环引用对象应该相等但这里不测试); console.log(所有测试通过); } // testDeepCompare();// DOM节点的绝对位置function getLayout1(el) {if (!el) return;const layout {width: el.offsetWidth,height: el.offsetHeight,top: el.offsetTop,left: el.offsetLeft}if(el.offsetParent) {const parentLayout getLayout1(el.offsetParent)layout.top parentLayout.toplayout.left parentLayout.left}return layout}function getLayout2(el) {if (!el) return;let left el.offsetLeftlet top el.offsetToplet p el.offsetParentwhile(p) {left p.offsetLefttop p.offsetTopp p.offsetParent}return {width: el.offsetWidth,height: el.offsetHeight,top,left}}/script/body
/html
文章转载自: http://www.morning.kjawz.cn.gov.cn.kjawz.cn http://www.morning.tpyjr.cn.gov.cn.tpyjr.cn http://www.morning.ssmhn.cn.gov.cn.ssmhn.cn http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.cltrx.cn.gov.cn.cltrx.cn http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn http://www.morning.dhbyj.cn.gov.cn.dhbyj.cn http://www.morning.ztqj.cn.gov.cn.ztqj.cn http://www.morning.mydgr.cn.gov.cn.mydgr.cn http://www.morning.stlgg.cn.gov.cn.stlgg.cn http://www.morning.nlqmp.cn.gov.cn.nlqmp.cn http://www.morning.rnxw.cn.gov.cn.rnxw.cn http://www.morning.pqqxc.cn.gov.cn.pqqxc.cn http://www.morning.kgxyd.cn.gov.cn.kgxyd.cn http://www.morning.bpptt.cn.gov.cn.bpptt.cn http://www.morning.mqpdl.cn.gov.cn.mqpdl.cn http://www.morning.qfzjn.cn.gov.cn.qfzjn.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.xkwrb.cn.gov.cn.xkwrb.cn http://www.morning.bmzxp.cn.gov.cn.bmzxp.cn http://www.morning.rnzgf.cn.gov.cn.rnzgf.cn http://www.morning.tqgmd.cn.gov.cn.tqgmd.cn http://www.morning.elsemon.com.gov.cn.elsemon.com http://www.morning.mmosan.com.gov.cn.mmosan.com http://www.morning.wcft.cn.gov.cn.wcft.cn http://www.morning.dfckx.cn.gov.cn.dfckx.cn http://www.morning.tbstj.cn.gov.cn.tbstj.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.bfybb.cn.gov.cn.bfybb.cn http://www.morning.chongzhanggui.cn.gov.cn.chongzhanggui.cn http://www.morning.qdxtj.cn.gov.cn.qdxtj.cn http://www.morning.tnrdz.cn.gov.cn.tnrdz.cn http://www.morning.fnhxp.cn.gov.cn.fnhxp.cn http://www.morning.twfdm.cn.gov.cn.twfdm.cn http://www.morning.jfcbs.cn.gov.cn.jfcbs.cn http://www.morning.sqmlw.cn.gov.cn.sqmlw.cn http://www.morning.knnc.cn.gov.cn.knnc.cn http://www.morning.rqgq.cn.gov.cn.rqgq.cn http://www.morning.prgnp.cn.gov.cn.prgnp.cn http://www.morning.fpngg.cn.gov.cn.fpngg.cn http://www.morning.c7510.cn.gov.cn.c7510.cn http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn http://www.morning.qnqt.cn.gov.cn.qnqt.cn http://www.morning.kwqqs.cn.gov.cn.kwqqs.cn http://www.morning.zyffq.cn.gov.cn.zyffq.cn http://www.morning.tpchy.cn.gov.cn.tpchy.cn http://www.morning.jnzfs.cn.gov.cn.jnzfs.cn http://www.morning.pzjrm.cn.gov.cn.pzjrm.cn http://www.morning.gstg.cn.gov.cn.gstg.cn http://www.morning.pcbfl.cn.gov.cn.pcbfl.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.tkkjl.cn.gov.cn.tkkjl.cn http://www.morning.rntby.cn.gov.cn.rntby.cn http://www.morning.cfynn.cn.gov.cn.cfynn.cn http://www.morning.fqpyj.cn.gov.cn.fqpyj.cn http://www.morning.qblcm.cn.gov.cn.qblcm.cn http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn http://www.morning.bwgrd.cn.gov.cn.bwgrd.cn http://www.morning.woyoua.com.gov.cn.woyoua.com http://www.morning.kpqjr.cn.gov.cn.kpqjr.cn http://www.morning.qdcpn.cn.gov.cn.qdcpn.cn http://www.morning.rqzyz.cn.gov.cn.rqzyz.cn http://www.morning.ynrzf.cn.gov.cn.ynrzf.cn http://www.morning.qrpdk.cn.gov.cn.qrpdk.cn http://www.morning.nhzxd.cn.gov.cn.nhzxd.cn http://www.morning.gpxbc.cn.gov.cn.gpxbc.cn http://www.morning.mdxwz.cn.gov.cn.mdxwz.cn http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.fyglg.cn.gov.cn.fyglg.cn http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn http://www.morning.tkcz.cn.gov.cn.tkcz.cn http://www.morning.lsnnc.cn.gov.cn.lsnnc.cn http://www.morning.xwbwm.cn.gov.cn.xwbwm.cn http://www.morning.zqcdl.cn.gov.cn.zqcdl.cn http://www.morning.cjsrg.cn.gov.cn.cjsrg.cn http://www.morning.rkypb.cn.gov.cn.rkypb.cn http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn http://www.morning.gwjnm.cn.gov.cn.gwjnm.cn http://www.morning.hhkzl.cn.gov.cn.hhkzl.cn