const list = [[723,263], [2,223,2, [55,78,963, [3434, 1889]]], [15, 38], [16,59]]
function formatWhile(list){
while(list.some(item => Array.isArray(item))) {
list = [].concat(...list)
}
return list
}
function formatReduce(list) {
return list.reduce((prev, total) => {
return Array.isArray(total) ? prev.concat(formatReduce(total)) : prev.concat(total)
}, [])
}
console.log(formatReduce(list))
// function formatWhile(list){
// while(list.some(item => Array.isArray(item))) {
// list = [].concat(...list)
// }
// return list
// }
// function formatReduce(list) {
// return list.reduce((prev, prop) => {
// return Array.isArray(prop) ? prev.concat(formatReduce(prop)) : prev.concat(prop)
// }, [])
// }
// function formatFor(list) {
// let array = []
// for(let i = 0; i < list.length; i++) {
// if (Array.isArray(list[i])) {
// array = array.concat(formatFor(list[i]))
// } else {
// array = array.concat(list[i])
// }
// }
// return array
// }
// console.log(formatFor(list))
// 最简便方法
// function formatWhile(list) {
// while(list.some(item => Array.isArray(item))) {
// list = [].concat(...list)
// }
// return list
// }
// // console.log(formatWhile(list))
// // 利用reduce 函数
// function formatReduce(list) {
// return list.reduce((prev, value) => {
// return Array.isArray(value) ? prev.concat(formatReduce(value)) : prev.concat(value)
// }, [])
// }
// // console.log(formatReduce(list))
// // 普通for循环
// function formatFor(list) {
// let array = []
// for (let i = 0; i< list.length; i++) {
// if (Array.isArray(list[i])) {
// array = array.concat(formatFor(list[i]))
// } else {
// array = array.concat(list[i])
// }
// }
// return array
// }
// console.log(formatFor(list))