
/* Return the position of the item toFind in array.
   returns -1 if toFind is not in the array. 
*/
function linearSearch(array, toFind)
{
   for (var i = 0; i < array.length; i++)
      if (array[i] == toFind)
      	 return i;
   
   return -1; 
}



/* Return the position of the item toFind in array.
   returns -1 if toFind is not in the array.  Array
   must be sorted 
*/
function binarySearch(array, toFind)
{
    var start = 0;
    var end = array.length;

    while (start <= end)
    {
        mid = Math.floor((start + end) / 2);

        if (array[mid] == toFind) 
           return mid;
        else if (array[mid] < toFind)
           start = mid + 1;
        else 
           end = mid - 1;
    }
    return -1;
}

