B
bH
Hi All,
Below is my efforts to show the recursive permutation of letters
in a single word.
I am using Windows XP and IE Browser
I am unsuccessful for 2 reasons:
The line number 22 reads as:
sub_permute(str.split(""), 0, str.length);
An error is noted "object does not support this property or method"
And second I need to declare an "out" that will show the
various permutations as an alert or within a text area.
TIA
bH
<html>
<head>
<title>PermuteAlpha</title>
<script type="text/javascript">
function PermuteAlpha() {
var str = document.getElementById("lttrsStr");
var ret = [];
function sub_permute(a, m, n){
var i, t;
if (m<n-1) {
sub_permute(a, m+1, n);
for (i=m+1;i<n;i++) {
t=a[m], a[m]=a, a=t;
sub_permute(a, m+1, n);
t=a[m], a[m]=a, a=t;
}
} else {
ret.push(a.join(""));
}
}
sub_permute(str.split(""), 0, str.length);
return ret;
}
</script>
</head>
<body>
<form>
<input maxLength=25 value="" type="text" id="lttrsStr"/><BR>
<button onclick= "PermuteAlpha()">Permute</button>
</form>
</body>
</html>
Below is my efforts to show the recursive permutation of letters
in a single word.
I am using Windows XP and IE Browser
I am unsuccessful for 2 reasons:
The line number 22 reads as:
sub_permute(str.split(""), 0, str.length);
An error is noted "object does not support this property or method"
And second I need to declare an "out" that will show the
various permutations as an alert or within a text area.
TIA
bH
<html>
<head>
<title>PermuteAlpha</title>
<script type="text/javascript">
function PermuteAlpha() {
var str = document.getElementById("lttrsStr");
var ret = [];
function sub_permute(a, m, n){
var i, t;
if (m<n-1) {
sub_permute(a, m+1, n);
for (i=m+1;i<n;i++) {
t=a[m], a[m]=a, a=t;
sub_permute(a, m+1, n);
t=a[m], a[m]=a, a=t;
}
} else {
ret.push(a.join(""));
}
}
sub_permute(str.split(""), 0, str.length);
return ret;
}
</script>
</head>
<body>
<form>
<input maxLength=25 value="" type="text" id="lttrsStr"/><BR>
<button onclick= "PermuteAlpha()">Permute</button>
</form>
</body>
</html>