js 数组去重排序
前段时间遇到的一个算法题,
var arr = [1,2,4,3,4,3,[12,2,4,5],[1,3,5,[234,432,5,3,2,5]]]
将上面的数组去重排序
let str = arr.toString() //先转换成字符串 let newArr = str.split(','); //根据 逗号分割再转换成一个数组 var a = [...new Set(newArr)] //es的语法去重 function insertionSort(array) { for (var i = 0; i < array.length; i++) { var key = eval("("+array[i]+")"); //将数组的字符串转换成数字 var j = i - 1; while ( array[j] > key) { array[j + 1] = array[j]; j--; } array[j + 1] = key; } return array; } console.log(insertionSort(a))
相关推荐
earthhouge 2020-06-25
Masimaro 2020-06-21
randy0 2020-11-17
lixiaotao 2020-10-07
美丽的泡沫 2020-09-08
nongfusanquan0 2020-08-18
hang0 2020-08-16
earthhouge 2020-08-15
算法改变人生 2020-07-28
troysps 2020-07-19
Broadview 2020-07-19
chenfei0 2020-07-18
风吹夏天 2020-07-07
yangjingdong00 2020-07-05
数据与算法之美 2020-07-05
shawsun 2020-07-04
数据与算法之美 2020-07-04