Skip to content

Commit c14bac2

Browse files
authoredAug 10, 2023
Merge pull request #2797 from chetannada/ltc-2810-js
Create 2810-faulty-keyboard.js
2 parents f5b7309 + 1900229 commit c14bac2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎javascript/2810-faulty-keyboard.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {string} s
3+
* @return {string}
4+
*/
5+
var finalString = function (s) {
6+
// initialize empty string str
7+
let str = "";
8+
9+
// loop thorugh the every character of string s
10+
for (let i = 0; i < s.length; i++) {
11+
12+
// if every character of string is i then reverse the previous string character and store in string str
13+
if (s[i] == 'i') {
14+
str = [...str].reverse().join('');
15+
} else {
16+
// else add every character of string s with str and store in string str
17+
str += s[i];
18+
}
19+
}
20+
21+
// return string str
22+
return str;
23+
};

0 commit comments

Comments
 (0)
Please sign in to comment.