forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunique.js
More file actions
52 lines (44 loc) · 815 Bytes
/
Copy pathunique.js
File metadata and controls
52 lines (44 loc) · 815 Bytes
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
// #START:dog
const dogs = [
{
name: 'max',
size: 'small',
breed: 'boston terrier',
color: 'black',
},
{
name: 'don',
size: 'large',
breed: 'labrador',
color: 'black',
},
{
name: 'shadow',
size: 'medium',
breed: 'labrador',
color: 'chocolate',
},
];
// #END:dogs
// #START:colors
function getColors(dogs) {
return dogs.map(dog => dog.color);
}
getColors(dogs);
// ['black', 'black', 'chocolate']
// #END:colors
// #START:unique
function getUnique(attributes) {
const unique = [];
for (const attribute of attributes) {
if (!unique.includes(attribute)) {
unique.push(attribute);
}
}
return unique;
}
const colors = getColors(dogs);
getUnique(colors);
// ['black', 'chocolate']
// #END:unique
export { getColors, getUnique };