Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8031411

Browse files
committed
Add a question
1 parent 2bb6186 commit 8031411

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,3 +1891,37 @@ const scramble = (str1, str2) => {
18911891
---
18921892

18931893
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1894+
1895+
## 55. Wave, wAve, waVe, wavE
1896+
1897+
Write a function that turns a given string into a wave! You will be passed a string and you must return that string in an array where each letter takes turns to become uppercase. The input string will always be lowercase but may be empty. If you encounter a whitespace then pass over it.
1898+
1899+
```js
1900+
const wave = str => {
1901+
// Your solution
1902+
};
1903+
1904+
console.log(wave('hello')); // ['Hello', 'hEllo', 'heLlo', 'helLo', 'hellO'];
1905+
console.log(wave(' gap ')); // [' Gap ', ' gAp ', ' gaP '];
1906+
console.log(wave('Two words')); // ['Two words', 'tWo words', 'twO words', 'two Words', 'two wOrds', 'two woRds', 'two worDs', 'two wordS'];
1907+
```
1908+
1909+
<details><summary>Solution</summary>
1910+
1911+
```js
1912+
const wave = str => {
1913+
const result = [];
1914+
const len = str.length;
1915+
for (let i = 0; i < len; i++) {
1916+
if (str[i] !== ' ')
1917+
result.push(str.slice(0, i) + str[i].toUpperCase() + str.slice(i + 1));
1918+
}
1919+
return result;
1920+
};
1921+
```
1922+
1923+
</details>
1924+
1925+
---
1926+
1927+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /