Created
December 8, 2020 19:37
-
-
Save danielcodes/ec112b5d46f40fc327c9c2f0afd46831 to your computer and use it in GitHub Desktop.
This file contains 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
// problem 3 | |
const products = [ | |
{name: "Stainless 10\"", weight: 1.5, price: 65, size: 10, id: 12}, | |
{name: "Stainless 12\"", weight: 1.8, price: 85, size: 12, id: 13}, | |
{name: "Carbon Steel 10\"", weight: 1.5, price: 75, size: 10, id: 23}, | |
{name: "Carbon Steel 12\"", weight: 1.95, price: 75, size: 12, id: 24}, | |
{name: "Nonstick 10\"", weight: 2.0, price: 70, size: 10, id: 3}, | |
{name: "Nonstick 12\"", weight: 2.0, price: 70, size: 12, id: 4} | |
]; | |
// 3 parts | |
// price >= 75, weight > 1.8 and obj with id as key and remove it from obj | |
const greaterThan75 = products.filter((prod) => { | |
return prod.price >= 75; | |
}); | |
const heavierThan18 = products.filter((prod) => { | |
return prod.weight > 1.8; | |
}); | |
const idAsKeys = products.reduce((acc, prod) => { | |
const {id, ...obj} = prod; | |
acc[id] = obj; | |
return acc; | |
}, {}); | |
console.log(greaterThan75); | |
console.log(heavierThan18); | |
console.log(idAsKeys); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment