Skip to content

Commit 116c123

Browse files
authored
Create 1374-generate-a-string-with-characters-that-have-odd-counts.js
1 parent b1d532f commit 116c123

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number} n
3+
* @return {string}
4+
*/
5+
const generateTheString = function(n, ch = 'a') {
6+
const odd = n % 2 === 1
7+
const code = ch.charCodeAt(0)
8+
if(odd) return ch.repeat(n)
9+
const nch = String.fromCharCode(code + 1), nnch = String.fromCharCode(code + 2)
10+
const even = (n / 2) % 2 === 0
11+
return generateTheString(even ? n / 2 - 1 : n / 2, nch) + generateTheString(even ? n / 2 + 1 : n / 2, nnch)
12+
};

0 commit comments

Comments
 (0)