Skip to content

Commit 864a4dc

Browse files
committed
Solución Reto 11
1 parent 242a191 commit 864a4dc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

retos/reto-11/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)