blob: d9ac4952f296147b317da4cb6b293fe6f288c7a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/usr/local/bin/node
//
// See ../README.md
//
//
// Run as: node ch-2.js < input-file
//
require ('readline')
. createInterface ({input: process . stdin})
. on ('line', line => {
let palindromes = {}
let out = ""
line = line . trim ()
for (let i = 0; i < line . length; i ++) {
for (let j = i; j < line . length; j ++) {
let string = line . substring (i, j + 1)
if (string == string . split ("") . reverse () . join ("")) {
if (!(string in palindromes)) {
out = out + string + " "
palindromes [string] = 1
}
}
}
}
console . log (out)
})
|