linlinyang
linlinyang
`function convert(num){ if(!num){ return ''; } return num % 10 + convert((num / 10) | 0); } var int = 12345; console.log(typeof convert(int));`
var arr = [1, 2, 3, 4, 5, 6, 7]; function reverse(arr,k){ k = k % arr.length; while(k--){ arr.unshift(arr.pop()); } } reverse(arr,3); console.log(arr);
`const list =[ {id:1,name:'部门A',parentId:0}, {id:2,name:'部门B',parentId:0}, {id:3,name:'部门C',parentId:1}, {id:4,name:'部门D',parentId:1}, {id:5,name:'部门E',parentId:2}, {id:6,name:'部门F',parentId:3}, {id:7,name:'部门G',parentId:2}, {id:8,name:'部门H',parentId:4} ]; function convert(arr){ const root = []; if(arr.length === 0){ return root; } const ids = [], childrens =...
var arr = [0,1,0,3,12]; function moveZero(arr){ var len = arr.length, zeroNums = 0; for(let i = 0; i < len; i++){ if(arr[i - zeroNums] === 0){ arr.push(...arr.splice(i - zeroNums++,1)); }...
/* * 题目:随机生成一个长度为 10 的整数类型的数组,例如 [2, 10, 3, 4, 5, 11, 10, 11, 20],将其排列成一个新数组,要求新数组形式如下,例如 [[2, 3, 4, 5], [10, 11], [20]]。 * * 理解:去重后把连续的数字组成一个数组,最后组成二维数组 */ var arr = [2, 10,...
` /* * 按位加 */ function add(num1,num2){ return num2 ? add(num1 ^ num2,(num1 & num2)
二分查找 ```js function findIndex(arr, target){ const len = arr.length; let left = 0; let right = len - 1; let ret = -1; while (left > 1) + left; const...
时间复杂度O(n) 空间复杂度L(n) ```js function arrFormat(arr: number[]): number[]{ const len: number = arr.length; const stack: number[] = [arr[0]]; const ret: number[] = new Array(len).fill(-1); const map: Record = arr.reduce((acc: Record, key:...
var obj = { a: { b: { c: { dd: 'abcdd' } }, d: { xx: 'adxx' }, e: 'ae' } }; function convert(target,preKey = '',result = {}){ let...