Вы можете просто отфильтровать String .
const a = [
["BOOT", 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 180.0, 180.0, 665.0, 725.0, 725.0, 735.5, 1155.5, 1155.5, 1155.5],
["IPP", 58.370000000000005, 58.379999999999995, 58.379999999999995, 140.38, 1073.975, 1184.5769999999998, 1724.927, 2086.9438, 2458.2437999999997, 4445.6398, 6067.0398, 6773.639799999999, 7098.639799999999, 7098.639799999999, 7098.639799999999],
["PPP", 1.5, 131.5, 131.5, 131.5, 131.5, 131.5, 135.0, 135.0, 135.0, 189.95, 231.54999999999998, 231.54999999999998, 556.5500000000001, 556.5500000000001, 806.5500000000001],
["Rental", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
["State owned", 26.116000000000003, 166.116, 169.014, 226.663, 226.663, 345.66300000000007, 524.963, 564.763, 567.4150000000001, 614.4150000000001, 989.4150000000002, 1079.415, 1099.415, 1119.815, 1119.815]
]
function removeZeros(array) {
return array.filter(function(arr) {
return !arr.filter(e => typeof e !== 'string').every(e => e === 0)
})
}
console.log(removeZeros(a))
Вы можете просто сделать String допустимым условием
const a = [
["BOOT", 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 180.0, 180.0, 665.0, 725.0, 725.0, 735.5, 1155.5, 1155.5, 1155.5],
["IPP", 58.370000000000005, 58.379999999999995, 58.379999999999995, 140.38, 1073.975, 1184.5769999999998, 1724.927, 2086.9438, 2458.2437999999997, 4445.6398, 6067.0398, 6773.639799999999, 7098.639799999999, 7098.639799999999, 7098.639799999999],
["PPP", 1.5, 131.5, 131.5, 131.5, 131.5, 131.5, 135.0, 135.0, 135.0, 189.95, 231.54999999999998, 231.54999999999998, 556.5500000000001, 556.5500000000001, 806.5500000000001],
["Rental", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
["State owned", 26.116000000000003, 166.116, 169.014, 226.663, 226.663, 345.66300000000007, 524.963, 564.763, 567.4150000000001, 614.4150000000001, 989.4150000000002, 1079.415, 1099.415, 1119.815, 1119.815]
]
function removeZeros(array) {
return array.filter(function(arr) {
return !arr.every(e => e === 0 || typeof e === 'string')
})
}
console.log(removeZeros(a))
Или сделать что-то, что не очень эффективно (но использует reduce()
, и это круто ):
const a = [
["BOOT", 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 180.0, 180.0, 665.0, 725.0, 725.0, 735.5, 1155.5, 1155.5, 1155.5],
["IPP", 58.370000000000005, 58.379999999999995, 58.379999999999995, 140.38, 1073.975, 1184.5769999999998, 1724.927, 2086.9438, 2458.2437999999997, 4445.6398, 6067.0398, 6773.639799999999, 7098.639799999999, 7098.639799999999, 7098.639799999999],
["PPP", 1.5, 131.5, 131.5, 131.5, 131.5, 131.5, 135.0, 135.0, 135.0, 189.95, 231.54999999999998, 231.54999999999998, 556.5500000000001, 556.5500000000001, 806.5500000000001],
["Rental", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
["State owned", 26.116000000000003, 166.116, 169.014, 226.663, 226.663, 345.66300000000007, 524.963, 564.763, 567.4150000000001, 614.4150000000001, 989.4150000000002, 1079.415, 1099.415, 1119.815, 1119.815]
]
function removeZeros(array) {
return array.reduce((a, c) => {
if (c.filter(e => e === 0).length !== c.length - 1) {
a.push(c)
}
return a
}, [])
}
console.log(removeZeros(a))
Или вы можете просто использовать «старомодный способ»:
const a = [
["BOOT", 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 180.0, 180.0, 665.0, 725.0, 725.0, 735.5, 1155.5, 1155.5, 1155.5],
["IPP", 58.370000000000005, 58.379999999999995, 58.379999999999995, 140.38, 1073.975, 1184.5769999999998, 1724.927, 2086.9438, 2458.2437999999997, 4445.6398, 6067.0398, 6773.639799999999, 7098.639799999999, 7098.639799999999, 7098.639799999999],
["PPP", 1.5, 131.5, 131.5, 131.5, 131.5, 131.5, 135.0, 135.0, 135.0, 189.95, 231.54999999999998, 231.54999999999998, 556.5500000000001, 556.5500000000001, 806.5500000000001],
["Rental", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
["State owned", 26.116000000000003, 166.116, 169.014, 226.663, 226.663, 345.66300000000007, 524.963, 564.763, 567.4150000000001, 614.4150000000001, 989.4150000000002, 1079.415, 1099.415, 1119.815, 1119.815]
]
function removeZeros(array) {
const ret = []
for (let i = 0; i < array.length; i++) {
let sum = 0
for (let j = 1; j < array[i].length; j++) {
sum += array[i][j]
}
if (sum) {
ret.push(array[i])
}
}
return ret
}
console.log(removeZeros(a))