-
Notifications
You must be signed in to change notification settings - Fork 10
/
chaining.js
executable file
·58 lines (54 loc) · 1.21 KB
/
chaining.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(function() {
"use strict";
var exampleTitle = "Chaining using arrays";
var bicycles = [{
name: "A fast bike",
type: "Road Bike"
}, {
name: "An even faster bike",
type: "Road Bike"
}, {
name: "A springy bike",
type: "Mountain Bike"
}, {
name: "A springier bike",
type: "Mountain Bike"
}, {
name: "An all-terain bike",
type: "Mountain Bike"
}, {
name: "A classy bike",
type: "Urban Bike"
}, {
name: "A modern bike",
type: "Urban Bike"
}, {
name: "A blue bike",
type: "Children Bike"
}, {
name: "A pink bike",
type: "Children Bike"
}, {
name: "A noisy bike",
type: "Children Bike"
}, {
name: "A clown bike",
type: "Children Bike"
}];
var bicycleTypeCountData = bicycles
.map(function(bicycle) {
return bicycle.type;
})
.filter(function(bicycleType) {
return bicycleType !== 'Children Bike';
})
.reduce(function(bicycleTypeCount, bicycleType) {
bicycleTypeCount[bicycleType] += 1;
return bicycleTypeCount;
}, {
"Road Bike": 0,
"Mountain Bike": 0,
"Urban Bike": 0
});
console.log(exampleTitle + " : " + JSON.stringify(bicycleTypeCountData));
}());