We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 242a191 commit 864a4dcCopy full SHA for 864a4dc
retos/reto-11/main.ts
@@ -0,0 +1,24 @@
1
+function getIndexsForPalindrome(word) {
2
+ let res: any = null
3
+ for (let a of Array.from({ length: word.length }).keys()) {
4
+ for (let b of Array.from({ length: word.length }).keys()) {
5
+ let swapped = [...word]
6
+ let aux = word[a]
7
+ swapped[a] = word[b]
8
+ swapped[b] = aux
9
+
10
+ let left = swapped.slice(0, Math.floor(word.length / 2)).join("")
11
+ let right = swapped.slice(Math.ceil(word.length / 2)).reverse().join("")
12
13
+ if (left == right) {
14
+ res = [[], [a, b]][+((a + b) > 0)]
15
+ return res;
16
+ }
17
18
19
+ return res
20
+}
21
22
+console.log(
23
+ getIndexsForPalindrome('abab')
24
+)
0 commit comments