文章 评论 浏览 28
Array.prototype.flat= function() { return [].concat(...this.map(item => (Array.isArray(item) ? item.flat() : [item]))); } Array.prototype.unique = function() { return [...new Set(this)] } const sort = (a, b) => a - b; console.log(arr.flat().unique().sort(sort)); // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
const max = Math.pow(2, 31) - 1; const min = -Math.pow(2, 31); const reverseNum = function(x) { var y = 0; while(x !== 0) { y = 10 * y + x % 10; x = ~~(x/10); } if (y > max) return 0; if (y < min) return 0; return y; };
文章 0 评论 0
接受
第 11 题:将数组扁平化并去除其中重复数据,最终得到一个升序且不重复的数组