Created
September 15, 2017 04:12
-
-
Save garrettmac/de32e799535fc96116f9a7c43430d610 to your computer and use it in GitHub Desktop.
MEDIUM BLOG POST - Javascript’s 3 Major Paradigms: The Five tenets of Functional Programming [part 3 of 4]
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
const vehicles = [ | |
{ make: ‘Honda’, model: ‘CR-V’, type: ‘suv’, price: 24045 }, | |
{ make: ‘Honda’, model: ‘Accord’, type: ‘sedan’, price: 22455 }, | |
{ make: ‘Mazda’, model: ‘Mazda 6’, type: ‘sedan’, price: 24195 }, | |
{ make: ‘Mazda’, model: ‘CX-9’, type: ‘suv’, price: 31520 }, | |
{ make: ‘Toyota’, model: ‘4Runner’, type: ‘suv’, price: 34210 }, | |
{ make: ‘Toyota’, model: ‘Sequoia’, type: ‘suv’, price: 45560 }, | |
{ make: ‘Toyota’, model: ‘Tacoma’, type: ‘truck’, price: 24320 }, | |
{ make: ‘Ford’, model: ‘F-150’, type: ‘truck’, price: 27110 }, | |
{ make: ‘Ford’, model: ‘Fusion’, type: ‘sedan’, price: 22120 }, | |
{ make: ‘Ford’, model: ‘Explorer’, type: ‘suv’, price: 31660 } | |
]; | |
const Makes=(arr,make)=>arr.filter(x=>x.make===make) | |
const CarType=(arr,type)=>arr.filter(x=>x.type===type) | |
let ArrayOfAllFords=Makes(vehicles,”Fords”) | |
let ArrayOfAllFordTrucks=Makes(vehicles,”trucks”) | |
//OUTPUTS | |
// ArrayOfAllFords is => [{ make: ‘Ford’, model: ‘F-150’, type: ‘truck’, price: 27110 }, { make: ‘Ford’, model: ‘Fusion’, type: ‘sedan’, price: 22120 }, { make: ‘Ford’, model: ‘Explorer’, type: ‘suv’, price: 31660 }] | |
//ArrayOfAllFordTrucks is => [{ make: ‘Ford’, model: ‘F-150’, type: ‘truck’, price: 27110 }] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment