Skip to content

Commit eb0a41f

Browse files
committed
Mejor solución
1 parent 1f47042 commit eb0a41f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

retos/reto-11/main.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function getIndexsForPalindrome(word) {
22
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()) {
3+
for (const a of Array.from({ length: word.length }).keys()) {
4+
for (const b of Array.from({ length: word.length }).keys()) {
55
let swapped = [...word]
66
let aux = word[a]
77
swapped[a] = word[b]
@@ -10,15 +10,17 @@ function getIndexsForPalindrome(word) {
1010
let left = swapped.slice(0, Math.floor(word.length / 2)).join("")
1111
let right = swapped.slice(Math.ceil(word.length / 2)).reverse().join("")
1212

13-
if (left == right) {
14-
res = [[], [a, b]][+((a + b) > 0)]
15-
return res;
16-
}
13+
res = [
14+
[
15+
null
16+
, [
17+
[]
18+
, [a, b]
19+
][+((a + b) > 0)]
20+
][+(left == right)]
21+
, res
22+
][+!!res]
1723
}
1824
}
1925
return res
20-
}
21-
22-
console.log(
23-
getIndexsForPalindrome('abab')
24-
)
26+
}

0 commit comments

Comments
 (0)