Advertisement
pcwizz

daul headed array search algorithm that returns array

Mar 3rd, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dualHeadedSearch(array, search){
  2.     var arrayLength =  array.length;
  3.     var output = new array();
  4.     for (var i = arrayLength - 1; i >= 0; i--) {
  5.         //starts from end back
  6.         if (array[i] == search && dualHeadedSearch(output, i) == false) {
  7.             output.push(i);
  8.         }
  9.         //starts from start forward
  10.         if(array[arrayLength - i] == search && dualHeadedSearch(output, i) == false){
  11.             output.push(arrayLength - i);
  12.         }
  13.     }
  14.     if (output.length > 0) {
  15.         return output;
  16.     }
  17.     return false;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement