forked from kalcifer/webpack-library-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (24 loc) · 730 Bytes
/
index.js
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
import _ from 'lodash';
import numRef from './ref.json';
function createTransalator() {
return {
numtoword: (num) => {
return num < 0 || num > 5 ? 'This is a failure' : converttoword(num);
},
wordtonum: (word) => {
const num = converttonum(word);
return num === -1 ? 'This is a failure' : num;
}
};
}
const converttoword = (num) => {
return _.reduce(numRef, (accum, ref) => {
return ref.num === num ? ref.word : accum;
}, '');
};
const converttonum = (word) => {
return _.reduce(numRef, (accum, ref) => {
return ref.word === word && word.toLowerCase() ? ref.num : accum;
}, -1);
};
export default createTransalator();