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
46 lines (43 loc) · 1.26 KB
/
Copy pathindex.js
File metadata and controls
46 lines (43 loc) · 1.26 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
var test = require('../util/test')(__filename);
var map = require('../../packages/object-map');
var compare = require('../../packages/collection-compare');
test('use value', function(t) {
t.plan(2);
var obj1 = {a: 3, b: 5, c: 9};
var result1 = map(obj1, function(key, value) {
return value + 1;
});
t.ok(compare(result1, {a: 4, b: 6, c: 10}));
var obj2 = {a: 3, b: 5, c: null};
var result2 = map(obj2, function(key, value) {
return Boolean(value);
});
t.ok(compare(result2, {a: true, b: true, c: false}));
t.end();
});
test('use key', function(t) {
t.plan(2);
var obj1 = {a: 3, b: 5, c: 9};
var result1 = map(obj1, function(key, value) {
return key;
});
t.ok(compare(result1, {a: 'a', b: 'b', c: 'c'}));
var obj2 = {'1': 3, '2': 5, '3': 9};
var result2 = map(obj2, Number);
t.ok(compare(result2, {'1': 1, '2': 2, '3': 3}));
t.end();
});
test('use key and value', function(t) {
t.plan(2);
var obj1 = {a: 3, b: 5, c: 9};
var result1 = map(obj1, function(key, value) {
return key + value;
});
t.ok(compare(result1, {a: 'a3', b: 'b5', c: 'c9'}));
var obj2 = {'1': 3, '2': 5, '3': 9};
var result2 = map(obj2, function(key, value) {
return value - key;
});
t.ok(compare(result2, {'1': 2, '2': 3, '3': 6}));
t.end();
});