forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (46 loc) · 1.46 KB
/
Copy pathindex.js
File metadata and controls
50 lines (46 loc) · 1.46 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var test = require('../util/test')(__filename);
var map = require('../../packages/object-map-values');
var compare = require('../../packages/collection-compare');
test('applies predicate using value argument', function(t) {
t.plan(2);
var obj1 = {a: 3, b: 5, c: 9};
var result1 = map(obj1, function(value) {
return value + 1;
});
t.ok(compare(result1, {a: 4, b: 6, c: 10}));
var obj2 = {a: 3, b: 0, c: null};
var result2 = map(obj2, function(value) {
return Boolean(value);
});
t.ok(compare(result2, {a: true, b: false, c: false}));
t.end();
});
test('applies predicate using key argument', function(t) {
t.plan(2);
var obj1 = {a: 3, b: 5, c: 9};
var result1 = map(obj1, function(value, key) {
return key;
});
t.ok(compare(result1, {a: 'a', b: 'b', c: 'c'}));
var obj2 = [1, 2, 3];
var result2 = map(obj2, function(value, key) {
return Boolean(Number(key)) || key;
});
t.ok(compare(result2, {0: '0', 1: true, 2: true}));
});
test('applies predicate using value and key arguments', function(t) {
t.plan(1);
var obj1 = {a: 3, b: 5, c: 9};
var result1 = map(obj1, function(value, key) {
return key + value;
});
t.ok(compare(result1, {a: 'a3', b: 'b5', c: 'c9'}));
});
test('applies predicate using all arguments', function(t) {
t.plan(1);
var obj1 = {a: 3, b: 5, c: 9};
var result1 = map(obj1, function(value, key, obj) {
return obj['b'] + value + key;
});
t.ok(compare(result1, {a: '8a', b: '10b', c: '14c'}));
});