JavaScript 30 — Day 4

Misty1636
Misty1636
Jul 19 · 6 min read
const ans = inventors.filter(item => item.year >= 1500 && item.year < 1600);console.table('1', ans);

const ans2 = inventors.map(item => `${item.first} ${item.last}`);console.table('2', ans2);

const ans3 = inventors.sort((a, b) => a.year - b.year);console.table('3', ans3);

const ans4 = inventors.reduce((total, obj) => total + obj.passed - obj.year, 0);console.table('4', ans4);

const ans5 = inventors.sort((a, b) => (a.passed - a.year) - (b.passed - b.year));inventors.forEach((item) => {  item.live = item.passed - item.year;});console.table('5', ans5);

const ans6 = document.querySelectorAll('.mw-category-group li a');const ary = [];ans6.forEach((item) => { ary.push(item.title); });ary.filter(item => item.indexOf('de') !== -1);

const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black, Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William'];const ans7 = people.sort((a, b) => (a.split(',')[1] > b.split(',')[1] ? 1 : -1));console.log('7', ans7);

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

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade