Skip to content

Commit 20c755b

Browse files
committed
Code style
1 parent 1a511d4 commit 20c755b

File tree

4 files changed

+39
-35
lines changed

4 files changed

+39
-35
lines changed

JavaScript/1-simple.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ Function.prototype.curry = function(...args) {
44
return this.bind(null, ...args);
55
};
66

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

12-
let persons = [
12+
const persons = [
1313
{ name: 'Marcus Aurelius', city: 'Rome', born: 121 },
1414
{ name: 'Victor Glushkov', city: 'Rostov on Don', born: 1923 },
1515
{ name: 'Ibn Arabi', city: 'Murcia', born: 1165 },
1616
{ name: 'Mao Zedong', city: 'Shaoshan', born: 1893 },
1717
{ name: 'Rene Descartes', city: 'La Haye en Touraine', born: 1596 }
1818
];
1919

20-
let p1 = projection.curry(['name', 'born']);
21-
let p2 = projection.curry(['name']);
20+
const p1 = projection.curry(['name', 'born']);
21+
const p2 = projection.curry(['name']);
2222

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

JavaScript/2-extended.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
'use strinct';
1+
'use strict';
22

33
Function.prototype.curry = function(...args) {
44
return this.bind(null, ...args);
55
};
66

7-
let persons = [
7+
const persons = [
88
{ name: 'Marcus Aurelius', city: 'Rome', born: 121 },
99
{ name: 'Victor Glushkov', city: 'Rostov on Don', born: 1923 },
1010
{ name: 'Ibn Arabi', city: 'Murcia', born: 1165 },
1111
{ name: 'Mao Zedong', city: 'Shaoshan', born: 1893 },
1212
{ name: 'Rene Descartes', city: 'La Haye en Touraine', born: 1596 }
1313
];
1414

15-
let md = {
15+
const md = {
1616
name: ['name'],
1717
place: ['city', upper, s => '<' + s + '>'],
1818
age: ['born', age]
1919
};
2020

21-
let projection = (meta, obj) => (Object
21+
const projection = (meta, obj) => (Object
2222
.keys(meta)
2323
.reduce((hash, key) => (hash[key] = meta[key]
2424
.reduce(
25-
(val, fn, i) => i === 0 ? obj[fn] : fn(val), null
25+
(val, fn, i) => (i === 0 ? obj[fn] : fn(val)), null
2626
), hash), {}
2727
)
2828
);
2929

30-
let p1 = projection.curry(md);
31-
let data = persons.map(p1);
30+
const p1 = projection.curry(md);
31+
const data = persons.map(p1);
3232
console.dir(data);
3333

3434
function capitalize(s) {
35-
return s.replace(/\w+/g, function(word) {
36-
return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
37-
});
35+
return s.replace(/\w+/g, (word) =>
36+
word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()
37+
);
3838
}
3939

4040
function upper(s) {

JavaScript/3-cached.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1-
'use strinct';
1+
'use strict';
22

3-
let persons = [
3+
const persons = [
44
{ name: 'Marcus Aurelius', city: 'Rome', born: 121 },
55
{ name: 'Victor Glushkov', city: 'Rostov on Don', born: 1923 },
66
{ name: 'Ibn Arabi', city: 'Murcia', born: 1165 },
77
{ name: 'Mao Zedong', city: 'Shaoshan', born: 1893 },
88
{ name: 'Rene Descartes', city: 'La Haye en Touraine', born: 1596 }
99
];
1010

11-
let md = {
11+
const md = {
1212
name: ['name'],
1313
place: ['city', upper, s => '<' + s + '>'],
1414
age: ['born', age]
1515
};
1616

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

26-
let p1 = projection(md);
27-
let data = persons.map(p1);
26+
const p1 = projection(md);
27+
const data = persons.map(p1);
2828
console.dir(data);
2929

3030
function capitalize(s) {
31-
return s.replace(/\w+/g, function(word) {
32-
return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
33-
});
31+
return s.replace(
32+
/\w+/g,
33+
word => (
34+
word.charAt(0).toUpperCase() +
35+
word.substr(1).toLowerCase()
36+
)
37+
);
3438
}
3539

3640
function upper(s) {

JavaScript/4-optimized.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
'use strinct';
1+
'use strict';
22

3-
let persons = [
3+
const persons = [
44
{ name: 'Marcus Aurelius', city: 'Rome', born: 121 },
55
{ name: 'Victor Glushkov', city: 'Rostov on Don', born: 1923 },
66
{ name: 'Ibn Arabi', city: 'Murcia', born: 1165 },
77
{ name: 'Mao Zedong', city: 'Shaoshan', born: 1893 },
88
{ name: 'Rene Descartes', city: 'La Haye en Touraine', born: 1596 }
99
];
1010

11-
let md = {
11+
const md = {
1212
name: ['name'],
1313
place: ['city', s => '<' + upper(s) + '>'],
1414
age: ['born', age]
1515
};
1616

1717
function projection(meta) {
18-
let keys = Object.keys(meta);
18+
const keys = Object.keys(meta);
1919
return obj => {
20-
let hash = {};
20+
const hash = {};
2121
let def, val;
2222
keys.forEach(key => {
2323
def = meta[key];
@@ -29,14 +29,14 @@ function projection(meta) {
2929
};
3030
}
3131

32-
let p1 = projection(md);
33-
let data = persons.map(p1);
32+
const p1 = projection(md);
33+
const data = persons.map(p1);
3434
console.dir(data);
3535

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

4242
function upper(s) {

0 commit comments

Comments
 (0)