forked from sgrouples/javascript-assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex02.js
More file actions
36 lines (31 loc) · 1.29 KB
/
Copy pathex02.js
File metadata and controls
36 lines (31 loc) · 1.29 KB
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
// you have array of groups.
// you need to display them in two panels: confirmed and unconfirmed.
// in each panel groups will be displayed in rows by two.
// Prepare your data in such a way, that you will have two arrays - one for confirmed, one for unconfirmed - and in each array you will have group ids grouped in arrays of two elements.
// don't use loops, use as many lodash functions as you can.
var _ = require('lodash');
var groups = [
{ 'id': 1, 'name': 'Green', 'confirmed': false },
{ 'id': 2, 'name': 'Yellow', 'confirmed': true },
{ 'id': 3, 'name': 'Blue', 'confirmed': false },
{ 'id': 4, 'name': 'Red', 'confirmed': false },
{ 'id': 5, 'name': 'Navy', 'confirmed': true },
{ 'id': 6, 'name': 'Pink', 'confirmed': true },
{ 'id': 7, 'name': 'Magenta', 'confirmed': true },
{ 'id': 8, 'name': 'Octarine', 'confirmed': true }
];
var group = function(groups){
return _.chain(groups)
.groupBy('confirmed')
.transform(function(result, value) {
var listOfIds = _.map(value, 'id');
return result.push(listOfIds);
}, [])
.map(function(group) {
return _.chunk(group, 2);
})
.reverse()
.value();
}
console.log( group(groups) );
// [ [ [ 2, 5 ], [ 6, 7 ], [ 8 ] ], [ [ 1, 3 ], [ 4 ] ] ]