-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcamelLetters.js
43 lines (35 loc) · 1019 Bytes
/
camelLetters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Write a function that accepts a String as an argument
The function should capitalize ONLY every other letter in the String
The function should then return the converted String.
*/
// Edge cases
/**
* "" => ""
* letter === character
*
* starting caps at letter index 0
*
* "hello" => "HeLlO"
* "yo eli" => "Yo eLi"
* "hello????" => "HeLlO????"
* "HELLO" => "HeLlO"
*/
const camelLetters = (str) => {
let camelStr = "";
for (let i = 0; i < str.length; i++) {
// const element = array[i];
// str = str[i].toUpperCase();
// str = str.replaceAt(i, str[i].toUpperCase());
// camelStr[i] = camelStr[i].toUpperCase();
// console.log(str[i])
camelStr += i % 2 === 0 ? str[i].toUpperCase() : str[i];
}
// console.log([...str].map((st, index) => index % 2 ? st.toUpperCase() : st).join(""))
// console.log(camelStr);
// return camelStr.join("");
return camelStr;
};
console.log(camelLetters("hello"));
// camelLetters("yo eli")
// camelLetters("hello????")