// 思谋科技面试算法
//[6,-3,-2,7,-15,1,2,2],连续子向量的最大和为8
let arr = [6,-3,-2,7,-15,1,2,2]
let len = arr.length,max = arr[0];
for(let i =0;i<len;i++){
let count = arr[i]
for(let j = i+1;j<len;j++){
count += arr[j]
max = Math.max(count,max);
}
}
console.log(max)
//数组扁平化
let arr2 = [[6,-3],[-2],7,[-15,1,[2]],2]
let res = []
bph(arr2)
function bph(arr){
for(let i =0;i<arr.length;i++){
if(arr[i] instanceof Array){
bph(arr[i])
}else{
res.push(arr[i])
}
}
}
console.log(res)