JSFiddle - React, Tailwind, and code Playground

by Exceeder

HTML

This is a binary prefix search tester. See JavaScript code.

JavaScript

Array.prototype.binaryPrefixFilter = function(find) {
      var low = 0, high = this.length - 1,
          i, el;
      while (low <= high) {
        i = Math.floor((low + high) / 2);
        el = this[i];
        if (el.indexOf(find)==0) { 
            //go left and right to find elements
            var start = i, end = i;
            while (--start > 0 && this[start].indexOf(find)==0);  
            while (++end < this.length && this[end].indexOf(find)==0);
            return this.splice(start+1,end-start-1);
        }
        if (el < find) { low = i + 1; }
           else {       high = i - 1; };
      }
      return [];
    }; 

var arrayOfStrings =  [
      "Patel Holder",
      "Ashlee Kirk",
      "Molly Moon",
      "Ethel Woods",
      "Alba Finley",
      "Calderon Carey",
      "Deborah Reid",
      "Jewel Franklin",
      "Stephanie Beard",
      "Hughes Ochoa",
      "Brock Mckay",
      "Watson Guerra",
      "Amparo Porter",
      "Whitley Crane",
      "Shannon Mcguire",
      "Hanson Burks",
      "Hull Barnes",
      "Alyson Paul",
      "Dolores Booker",
      "Hansen Mann",
      "Velma Owens",
      "Etta Livingston",
      "Judith Shepherd",
      "Odessa Bernard",
      "Kristine Russell",
      "Marianne Oconnor",
      "Amanda Roberts",
      "Katie Mosley",
      "Harrell Perkins",
      "Forbes Owen",
      "Aline Jacobs",
      "Johnston Riggs",
      "Rosario Gill",
      "Kirk Dodson",
      "Pansy Shepard",
      "Mildred Farrell",
      "Christa Newman",
      "Hunter Jensen",
      "Stevens Rosa",
      "Rene England",
      "Terri Thomas",
      "Desiree Morton",
      "Eloise Vang",
      "Lucille Fisher",
      "Miriam White",
      "Franklin Barber",
      "Marlene Allen",
      "Craft Reeves",
      "Kerri Carr",
      "Murphy Mckee",
      "Frank Clayton",
      "Diana Little",
      "Olivia Boyd",
      "Lorrie Simpson",
      "Kellie Roman",
      "Delaney King",
      "Blankenship Bentley",
      "Teri Knapp",
     ...