Last active
January 24, 2020 11:04
-
-
Save ronaldgreeff/01fa03b8532c18259fef93c187631f2f to your computer and use it in GitHub Desktop.
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
// for loops are the most performant, but these methods are useful given specific tasks | |
const items = [ | |
{ name: 'Bike', price: 100 }, | |
{ name: 'TV', price: 200 }, | |
{ name: 'Album', price: 10 }, | |
{ name: 'Book', price: 5 }, | |
{ name: 'Phone', price: 500 }, | |
{ name: 'Computer', price: 1000 }, | |
{ name: 'Keyboard', price: 25 }, | |
] | |
// filter | |
// const filteredItems = items.filter((item) => { | |
// return item.price <= 100 | |
// }) | |
// map | |
// const itemNames = items.map((item) => { | |
// return item.name | |
// }) | |
// find | |
// const foundItem = items.find((item) => { | |
// return item.name === 'Book' | |
// }) | |
// forEach | |
// items.forEach((item) => { | |
// console.log(item.name) | |
// }) | |
// some (any) | |
// const hasInexpensiveItems = items.some((item) => { | |
// return item.price <= 100; | |
// }) | |
// every (all) | |
// const hasInexpensiveItems = items.every((item) => { | |
// return item.price <= 100; | |
// }) | |
// reduce | |
// inital parameter is what to reduce into + starting value, 0) | |
// const total = items.reduce((currentTotal, item) => { | |
// return item.price + currentTotal; | |
// }, 0) | |
// includes | |
// const l = [1,2,3,4,5] | |
// const includesTwo = l.includes(2) | |
console.log(includesTwo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment