forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapSpread.js
More file actions
36 lines (29 loc) · 801 Bytes
/
Copy pathmapSpread.js
File metadata and controls
36 lines (29 loc) · 801 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
/* eslint-disable no-unused-vars */
const filters = new Map()
.set('color', 'black')
.set('breed', 'labrador');
// START:get
function getAppliedFilters(filters) {
const applied = [...filters].map(([key, value]) => {
return `${key}:${value}`;
});
return `Your filters are: ${applied.join(', ')}.`;
}
// 'Your filters are: color:black, breed:labrador.'
// END:get
function sortByKey(a, b) {
return a[0] > b[0] ? 1 : -1;
}
// START:sort
function getSortedAppliedFilters(filters) {
const applied = [...filters]
.sort(sortByKey)
.map(([key, value]) => {
return `${key}:${value}`;
})
.join(', ');
return `Your filters are: ${applied}.`;
}
// 'Your filters are: breed:labrador, color:black.'
// END:sort
export { getAppliedFilters, getSortedAppliedFilters };