COP3530 Assignment 2 - Pt2

by joseph_kanawall2400

HTML

Value:
<input type="input" id="val_to_search" value="60" />
<br/>
<input type="button" value="Pick One" onClick="SearchArray(array, parseInt(getElementById('val_to_search').value));" />
<br/>
<br/> The algorithm is O(n) with 1 operation per n

JavaScript

var count = 0;
var array = new Array(1000);

for (x = 0; x < array.length; x++) {
	array[x] = Math.floor(Math.random() * 100) + 1;
}

function SearchArray(array, value) {
    count = 0;
    var output = "";
    for (var x = 0; x < 1000; x++) {
        count++;
        if (array[x] == value) {
            output += x + ", ";
        }
    }
    alert(value + " is in array at indexes: " + output);
    alert("O Count: " + count);
}