Skip to content

Commit 3cfe448

Browse files
committed
Rewrite upperCapital
1 parent b8ed7c4 commit 3cfe448

5 files changed

Lines changed: 15 additions & 20 deletions

File tree

JavaScript/2-composition.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ const compose = (f1, f2) => x => f2(f1(x));
44

55
// Usage
66

7-
const upperCapital = s => s.replace(
8-
/\w+/g,
9-
word => word.charAt(0).toUpperCase() + word.substr(1)
10-
);
7+
const upperCapital = s => s.split(' ')
8+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
9+
.join(' ');
1110

1211
const lower = s => (typeof s === 'string' ? s.toLowerCase() : '');
1312

JavaScript/3-arguments.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ const compose = (f1, f2) => (...args) => f2(f1(...args));
44

55
// Usage
66

7-
const upperCapital = s => s.replace(
8-
/\w+/g,
9-
word => word.charAt(0).toUpperCase() + word.substr(1)
10-
);
7+
const upperCapital = s => s.split(' ')
8+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
9+
.join(' ');
1110

1211
const lower = s => (typeof s === 'string' ? s.toLowerCase() : '');
1312

JavaScript/4-multiple.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ const compose = (...fns) => (...args) => (
66

77
// Usage
88

9-
const upperCapital = s => s.replace(
10-
/\w+/g,
11-
word => word.charAt(0).toUpperCase() + word.substr(1)
12-
);
9+
const upperCapital = s => s.split(' ')
10+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
11+
.join(' ');
1312

1413
const lower = s => (typeof s === 'string' ? s.toLowerCase() : '');
1514

JavaScript/5-loop.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ const compose = (...fns) => (...args) => {
1212

1313
// Usage
1414

15-
const upperCapital = s => s.replace(
16-
/\w+/g,
17-
word => word.charAt(0).toUpperCase() + word.substr(1)
18-
);
15+
const upperCapital = s => s.split(' ')
16+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
17+
.join(' ');
1918

2019
const lower = s => (typeof s === 'string' ? s.toLowerCase() : '');
2120

JavaScript/6-recursive.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ const compose = (...fns) => (...args) => {
1010

1111
// Usage
1212

13-
const upperCapital = s => s.replace(
14-
/\w+/g,
15-
word => word.charAt(0).toUpperCase() + word.substr(1)
16-
);
13+
const upperCapital = s => s.split(' ')
14+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
15+
.join(' ');
1716

1817
const lower = s => (typeof s === 'string' ? s.toLowerCase() : '');
1918

0 commit comments

Comments
 (0)