Skip to content

Commit 34ddfbc

Browse files
committed
Rename and refactor
1 parent 6742d85 commit 34ddfbc

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ const persons = [
1010

1111
const md = {
1212
name: ['name'],
13-
place: ['city', s => '<' + upper(s) + '>'],
13+
place: ['city', s => '<' + s.toUpperCase() + '>'],
1414
born: ['born'],
1515
age: ['born', age]
1616
};
1717

18+
function age(year) {
19+
return new Date().getFullYear() - new Date(year + '').getFullYear();
20+
}
21+
1822
const projection = (meta) => {
1923
const keys = Object.keys(meta);
2024
return obj => {
2125
const hash = {};
22-
let def, val;
2326
keys.forEach(key => {
24-
def = meta[key];
25-
val = obj[def[0]];
27+
const def = meta[key];
28+
let val = obj[def[0]];
2629
if (def.length > 1) val = def[1](val);
2730
hash[key] = val;
2831
});
@@ -33,21 +36,3 @@ const projection = (meta) => {
3336
const p1 = projection(md);
3437
const data = persons.map(p1);
3538
console.dir(data);
36-
37-
function capitalize(s) {
38-
return s.replace(/\w+/g, (word) =>
39-
word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()
40-
);
41-
}
42-
43-
function upper(s) {
44-
return typeof(s) === 'string' ? s.toUpperCase() : '';
45-
}
46-
47-
function age(year) {
48-
return new Date().getFullYear() - new Date(year + '').getFullYear();
49-
}
50-
51-
function inc(x) {
52-
return ++x;
53-
}

0 commit comments

Comments
 (0)