-
Notifications
You must be signed in to change notification settings - Fork 4
/
IT2project.html
46 lines (31 loc) · 874 Bytes
/
IT2project.html
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
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<title>second</title>
<script type="text/javascript">
var word=prompt("enter a string");
function permute (word) {
if (word.length < 2) {
return [word];
} else {
var permutations = [];
for (var i = 0; i < word.length; i++) {
var letter = word[i];
if (word.indexOf(letter) != i)
continue;
var shorterWord = word.substr(0, i) + word.substr(i + 1, word.length - 1);
var shortwordArray = permute(shorterWord);
for (var j = 0; j < shortwordArray.length; j++) {
permutations.push(letter + shortwordArray[j]);
}
}
return permutations;
}
}
alert(permute(word));
</script>
</head>
<body>
</div>
</body>
</html>