Skip to content

Commit 4bf22bb

Browse files
committed
mexican wave: done
1 parent f8fb5c6 commit 4bf22bb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

mexican_wave/main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
function wave(str){
2+
return [...str].map((val, idx) => `${str.slice(0, idx)}${val.toUpperCase()}${str.slice(idx + 1)}`).filter(x => x !== str);
3+
return [...str].reduce((acc, cur, idx) => (cur.trim() ? acc.push(`${str.slice(0, idx)}${cur.toUpperCase()}${str.slice(idx + 1)}`) : acc, acc), []);
4+
25
const result = [];
36
for(let i = 0; i < str.length; i++) {
4-
const split = str.split('');
5-
split[i] = split[i].toUpperCase();
6-
result.push(split.join(''));
7+
if(str[i].trim()) {
8+
result.push(`${str.slice(0, i)}${str[i].toUpperCase()}${str.slice(i + 1, str.length)}`);
9+
}
710
}
811
return result;
912
}

mexican_wave/main.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ describe('Mexican wave test with full text', () => {
1616
test('wav returns ["Wav", "wAv", "waV"]', () => {
1717
expect(wave('wav')).toStrictEqual(['Wav','wAv','waV']);
1818
});
19+
test("hello returns ['Hello', 'hEllo', 'heLlo', 'heLlo', 'hellO']", () => {
20+
expect(wave('hello')).toStrictEqual(['Hello', 'hEllo', 'heLlo', 'helLo', 'hellO']);
21+
});
22+
});
23+
24+
describe('Mexican wave test with full text and blank', () => {
25+
test('wa v returns ["Wa v", "wA v", "wa V"]', () => {
26+
expect(wave('wa v')).toStrictEqual(['Wa v', 'wA v', 'wa V']);
27+
});
1928
});

0 commit comments

Comments
 (0)