|
-
 Originally Posted by marlopax
PHP Code:
var my_array:Array = new Array("a", "a", "a", "b", "a", "a", "a", "a", "a", "v", "a", "a", "a", "a", "a", "a", "a");
function count_by_search(data_arr:Array, str:String) {
Array.prototype.copy = Array.prototype.slice;
var arr = data_arr.copy();
var i = 0;
var count = 0;
while (i<arr.length) {
var j = 0;
while (j<arr.length) {
if (arr[j] == str) {
arr.splice(j,1);
count++;
} else {
j++;
}
}
i++;
}
if (count>0) {
return "Duplicate found "+str+": "+(count);
} else if (count == 0) {
return "Invalid search";
} else {
return "No duplicate found";
}
}
Array.prototype.count_by_search = function(str) {
Array.prototype.copy = Array.prototype.slice;
var arr = this.copy();
var i = 0;
var count = 0;
while (i<arr.length) {
var j = 0;
while (j<arr.length) {
if (arr[j] == str) {
arr.splice(j,1);
count++;
} else {
j++;
}
}
i++;
}
if (count>0) {
return "Duplicate found "+str+": "+(count);
} else if (count == 0) {
return "Invalid search";
} else {
return "No duplicate found";
}
};
var count_search;
trace("my_array.count_by_search(\"string\");\n");
count_search = my_array.count_by_search("b");
trace(count_search);
count_search = my_array.count_by_search("a");
trace(count_search);
count_search = my_array.count_by_search("l");
trace(count_search);
trace("\ncount_by_search(my_array, \"string\");\n");
count_search = count_by_search(my_array, "a");
trace(count_search);
count_search = count_by_search(my_array, "b");
trace(count_search);
count_search = count_by_search(my_array, "l");
trace(count_search);
That is not the correct way. This will be the right way.
Sorry for my mistake..
marlopax
Ah, that works as well. No worries, thank you again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|