палиндром

 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
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>палиндром</title>
</head>
<body>
<script type="text/javascript">
function test_check()
{
var str = document.getElementById('in').value;
var arr = [];
var count = 0;
var out = '';
for (var key in str)
arr[str[key]] = (typeof arr[str[key]] == "undefined") ? true : (arr[str[key]] == true) ? false : true;
for (var key in arr)
if (arr[key] == true ) count++;
if (str.length % 2) out = (count == 1) ? 'ok' : 'not';
else out = (count == 0) ? 'ok' : 'not';
document.getElementById("out").innerHTML = str.length + ' ' + count + ' ' + out;
}
</script>
<form onsubmit="test_check(); return false">
<p><b>Введите текст:</b></p>
<p><textarea rows="10" cols="45" name="text" id="in"></textarea></p>
<p><input type="submit" value="Проверить"></p>
</form>
<div id="out"></div>
</body>
</html>