Skip to content

Commit 48d5c29

Browse files
authored
Create 848-shifting-letters.js
1 parent 316ce9c commit 48d5c29

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

848-shifting-letters.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string} S
3+
* @param {number[]} shifts
4+
* @return {string}
5+
*/
6+
const shiftingLetters = function(S, shifts) {
7+
let suffixSum = 0,
8+
result = "";
9+
for (let i = S.length - 1; i >= 0; i--) {
10+
suffixSum += shifts[i];
11+
let ascii = S[i].charCodeAt() - 97;
12+
result = String.fromCharCode(97 + ((ascii + suffixSum) % 26)) + result;
13+
}
14+
return result;
15+
};

0 commit comments

Comments
 (0)