# 04 Array Cardio ? 指南一

## 炫酷的调试技巧

console.table(thing)

## 过程指南

1. 筛选 16 世纪出生的发明家
2. 展示他们的姓和名
3. 把他们按照年龄从大到小进行排序
4. 计算所有的发明家加起来一共活了多少岁
5. 按照他们活了多久来进行排序
6. 筛选出一个网页里含有某个词语的标题
7. 按照姓氏来对发明家进行排序
8. 统计给出数组中各个物品的数量

## 相关知识

### filter

const __fifteen = inventors.filter(function(inventor){if(inventor.year >=1500&& inventor.year <1600){returntrue;}else{returnfalse;}});console.table(__fifteen);

const fifteen = inventors.filter(inventor =>(inventor.year >=1500&& inventor.year <1600));console.table(fifteen);

### map

map 形象的理解就是，把数组中的每个元素进行处理后，返回一个新的数组。

// 展示数组对象  inventors 里发明家的姓名  const fullNames = inventors.map(inventor => inventor.first +' '+ inventor.last);

### sort

const __ordered = inventors.sort((a, b)=>(a > b)?1:-1);console.table(__ordered);

### filter 和 map 的结合使用

// https://book.douban.com/tag/webconst cate = document.querySelectorAll('.subject-list h2 a');const book = links.map(link => link.title).filter(title => title.includes('CSS'));

var links =Array.from(document.querySelectorAll('#ordersContainer div.order div.a-row > a.a-link-normal'))var object = order.map( order =>{var a ={};var time = order.querySelector('.order-info span.value').textContent.trim();var title = order.querySelector('div.a-row > a.a-link-normal').textContent.trim();a["time"]= time;return a;})

### reduce

[0,1,2,3,4].reduce(function(previousValue, currentValue, index, array){return previousValue + currentValue;});

const data =['car','car','truck','truck','bike','walk','car','van','bike','walk','car','van','car','truck'];const reduce = data.reduce((obj, item)=>{if(!obj[item]){          obj[item]=0;}          obj[item]++;return obj;},{});  console.log(reduce);