Skip to content

Commit 8cf7f37

Browse files
committed
Optimizations
1 parent 20c755b commit 8cf7f37

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

JavaScript/1-simple.js

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

77
const projection = (fields, obj) => (Object
8-
.keys(obj).filter(field => fields.indexOf(field) >= 0)
8+
.keys(obj).filter(field => fields.includes(field))
99
.reduce((hash, key) => (hash[key] = obj[key], hash), {})
1010
);
1111

@@ -20,5 +20,5 @@ const persons = [
2020
const p1 = projection.curry(['name', 'born']);
2121
const p2 = projection.curry(['name']);
2222

23-
const data = persons.map(p1).map(p2);
23+
const data = persons.map(p2).map(p2);
2424
console.dir(data);

JavaScript/3-cached.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const md = {
1414
age: ['born', age]
1515
};
1616

17-
function projection(meta) {
17+
const projection = (meta) => {
1818
const keys = Object.keys(meta);
1919
return obj => keys.reduce((hash, key) => (
2020
hash[key] = meta[key].reduce(
2121
(val, fn, i) => (i === 0 ? obj[fn] : fn(val)), null
2222
), hash
2323
), {});
24-
}
24+
};
2525

2626
const p1 = projection(md);
2727
const data = persons.map(p1);

JavaScript/4-optimized.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const md = {
1414
age: ['born', age]
1515
};
1616

17-
function projection(meta) {
17+
const projection = (meta) => {
1818
const keys = Object.keys(meta);
1919
return obj => {
2020
const hash = {};
@@ -27,7 +27,7 @@ function projection(meta) {
2727
});
2828
return hash;
2929
};
30-
}
30+
};
3131

3232
const p1 = projection(md);
3333
const data = persons.map(p1);

0 commit comments

Comments
 (0)