This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cars = [ | |
{ name: 'Mustang', maker: 'Ford', isSuv: false }, | |
{ name: 'EcoSport', maker: 'Ford', isSuv: true }, | |
{ name: 'CR-V', maker: 'Honda', isSuv: true } | |
]; | |
const match = _.filter(cars, car => { return car.isSuv; }); | |
console.log(match); | |
// 0: {name: "EcoSport", maker: "Ford", isSuv: true} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cars = [ | |
{ name: 'Mustang', cost: 50000, isSuv: false}, | |
{ name: 'EcoSport', cost: 40000, isSuv: true}, | |
{ name: 'CR-V', cost: 35000, isSuv: true} | |
]; | |
const totalCosts = _.sumBy(cars, car => { | |
return car.cost; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cars = [ | |
{ name: 'Mustang', cost: 50000, isSuv: false}, | |
{ name: 'EcoSport', cost: 40000, isSuv: true}, | |
{ name: 'CR-V', cost: 35000, isSuv: true} | |
]; | |
const totalCosts = _.sumBy(cars, car => { | |
return car.isSuv ? car.cost : 0; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cars = [ | |
{ name: 'Mustang', cost: 50000, isSuv: false}, | |
{ name: 'EcoSport', cost: 40000, isSuv: true}, | |
{ name: 'CR-V', cost: 35000, isSuv: true} | |
]; | |
const totalCosts = _.sumBy(cars, car => { | |
return car.cost > 39000 ? car.cost : 0; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cars = [ | |
{ name: 'Mustang', cost: 50000, isSuv: false}, | |
{ name: 'EcoSport', cost: 40000, isSuv: true}, | |
{ name: 'CR-V', cost: 35000, isSuv: true} | |
]; | |
const totalCosts = _.sumBy(cars, car => { | |
return car.cost > 35000 ? car.cost : 0; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMoment(t){var e=document.createElement("script");e.onload=t,e.src="http://bit.ly/moment-2-24-0-min",document.body.appendChild(e)} | |
getMoment(() => { | |
// put your code here... | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const body = document.getElementsByTagName('body')[0]; | |
body.addEventListener('click', () => { | |
console.log('The <body /> tag was clicked'); | |
}); | |
// on each click of the page, you will see: "The <body /> tag was clicked" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body.removeEventListener('click'); | |
// Uncaught TypeError: Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body.removeEventListener('click', () => {}); | |
// on each click of the page, you will STILL see: "The <body /> tag was clicked" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bodyClickHandler () { | |
console.log('The <body /> tag was clicked'); | |
}; | |
const body = document.getElementsByTagName('body')[0]; | |
body.addEventListener('click', bodyClickHandler); | |
// on each click of the page, you will see: "The <body /> tag was clicked" |