File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const ages = persons => {
4+ // Use for..in to calculate age for each person
5+ // For example ages({
6+ // lenin: { born: 1870, died: 1924 },
7+ // mao: { born: 1893, died: 1976 },
8+ // gandhi: { born: 1869, died: 1948 },
9+ // hirohito: { born: 1901, died: 1989 },
10+ // })
11+ // should return {
12+ // lenin: 54,
13+ // mao: 83,
14+ // gandhi: 79,
15+ // hirohito: 88,
16+ // }
17+ } ;
18+
19+ module . exports = { ages } ;
Original file line number Diff line number Diff line change 1+ ({
2+ name: 'ages',
3+ length: [150, 190],
4+ cases: [
5+ [
6+ {
7+ lenin: { born: 1870, died: 1924 },
8+ mao: { born: 1893, died: 1976 },
9+ gandhi: { born: 1869, died: 1948 },
10+ hirohito: { born: 1901, died: 1989 },
11+ }, {
12+ lenin: 54,
13+ mao: 83,
14+ gandhi: 79,
15+ hirohito: 88,
16+ }
17+ ]
18+ ],
19+ test: ages => {
20+ const src = ages.toString();
21+ if (!src.includes('for (')) throw new Error('Use for..in loop');
22+ if (!src.includes(' in ')) throw new Error('Use for..in loop');
23+ }
24+ })
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const ages = persons => {
4+ const data = { } ;
5+ for ( const name in persons ) {
6+ const person = persons [ name ] ;
7+ data [ name ] = person . died - person . born ;
8+ }
9+ return data ;
10+ } ;
11+
12+ module . exports = { ages } ;
You can’t perform that action at this time.
0 commit comments