Skip to content

Commit 1d968d0

Browse files
committed
mapValues util and unit test
1 parent dbe1a17 commit 1d968d0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/utils/mapValues.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function mapValues(obj, fn) {
2+
return Object.keys(obj).reduce((result, key) => {
3+
result[key] = fn(obj[key], key);
4+
return result;
5+
}, {});
6+
}

test/utils/mapValues.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import expect from 'expect';
2+
import mapValues from '../../src/utils/mapValues';
3+
4+
describe('Utils', () => {
5+
describe('mapValues', () => {
6+
it('should return object with mapped values', () => {
7+
const test = { 'a': 1, 'b': 2 };
8+
expect(mapValues(test, val => val * 3)).toEqual({ 'a': 3, 'b': 6 });
9+
});
10+
});
11+
});
12+

0 commit comments

Comments
 (0)