Skip to content

Commit 9cec790

Browse files
committed
Update examples
2 parents 0fe467d + 8cf7f37 commit 9cec790

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

JavaScript/1-simple.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Function.prototype.curry = function(...args) {
55
};
66

77
const projection = (fields, obj) => (
8-
Object
9-
.keys(obj)
8+
Object.keys(obj)
109
.filter(field => fields.includes(field))
1110
.reduce((hash, key) => (hash[key] = obj[key], hash), {})
1211
);
@@ -22,5 +21,5 @@ const persons = [
2221
const p1 = projection.curry(['name', 'born']);
2322
const p2 = projection.curry(['name']);
2423

25-
const data = persons.map(p1).map(p2);
24+
const data = persons.map(p2).map(p2);
2625
console.dir(data);

JavaScript/2-extended.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ const md = {
1818
age: ['born', age]
1919
};
2020

21-
const projection = (meta, obj) => (Object
22-
.keys(meta)
23-
.reduce((hash, key) => (hash[key] = meta[key]
24-
.reduce(
21+
const projection = (meta, obj) => (
22+
Object.keys(meta).reduce((hash, key) => (
23+
hash[key] = meta[key].reduce(
2524
(val, fn, i) => (i === 0 ? obj[fn] : fn(val)), null
26-
), hash), {}
27-
)
25+
), hash
26+
), {})
2827
);
2928

3029
const p1 = projection.curry(md);
@@ -33,7 +32,7 @@ console.dir(data);
3332

3433
function capitalize(s) {
3534
return s.replace(/\w+/g, (word) =>
36-
word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()
35+
word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()
3736
);
3837
}
3938

JavaScript/4-optimized.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ console.dir(data);
3636

3737
function capitalize(s) {
3838
return s.replace(/\w+/g, (word) =>
39-
word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()
39+
word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()
4040
);
4141
}
4242

0 commit comments

Comments
 (0)