(1)
复习map和reduce,解题更方便: 传参的reduce
let items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]],
ruleKey = "color",
ruleValue = "silver"
const map = {
type: 0,
color: 1,
name: 2
}
let sum = items.reduce((acc, cur) => {
if(cur[map[ruleKey]] === ruleValue){
acc++
}
return acc
},0) // 传入初始值
console.log(sum);
(2)3.08
3.09
B: 指的是for(let i = 0; ;)
C: for 循环的变量不一定非要是数字类型的
D: 与A表达意思一样,三个部分都可有可无,但是分号一定要有。
3.10