-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
今天上班没事做,练习了一下算法
递归
var data = [1, 2, [3, 4, [5]], 6, [7, [8, 9, [10, 11, [12]]]]];
window.onload = function() {
//递归
var result = []
fillArray(data, result)
console.log(result)
}
//递归
function fillArray(array, result) {
array.forEach(function(i) {
if (i instanceof Array) {
fillArray(i, result)
} else {
result.push(i)
}
})
}ES5数组去重
function delRepeat(array) {
var result = []
array.forEach(function(i, k) {
if (result.indexOf(i) == -1) {
result.push(i)
}
})
return result
}ES6数组去重
function delRepeat(items) {
return [...new Set(items)];
}获取m到n的随机数
function fn(m,n){
return parseInt(Math.random()*(n-m))+m;
}Yeahax