find the longest common prefix among a list of inputs. for efficiency, this function starts off by using the shortest string among inputs, then performs a binary search.
inputs
import { assertEquals } from "jsr:@std/assert"assertEquals(commonPrefix([ "C:/Hello/World/This/Is/An/Example/Bla.cs", "C:/Hello/World/This/Is/Not/An/Example/", "C:/Hello/Earth/Bla/Bla/Bla",]), "C:/Hello/")assertEquals(commonPrefix([ "C:/Hello/World/This/Is/An/Example/Bla.cs", "C:/Hello/World/This/is/an/example/bla.cs", "C:/Hello/World/This/Is/Not/An/Example/",]), "C:/Hello/World/This/")assertEquals(commonPrefix([ "C:/Hello/World/Users/This/Is/An/Example/Bla.cs", "C:/Hello/World Users/This/Is/An/example/bla.cs", "C:/Hello/World-Users/This/Is/Not/An/Example/",]), "C:/Hello/World") Copy
import { assertEquals } from "jsr:@std/assert"assertEquals(commonPrefix([ "C:/Hello/World/This/Is/An/Example/Bla.cs", "C:/Hello/World/This/Is/Not/An/Example/", "C:/Hello/Earth/Bla/Bla/Bla",]), "C:/Hello/")assertEquals(commonPrefix([ "C:/Hello/World/This/Is/An/Example/Bla.cs", "C:/Hello/World/This/is/an/example/bla.cs", "C:/Hello/World/This/Is/Not/An/Example/",]), "C:/Hello/World/This/")assertEquals(commonPrefix([ "C:/Hello/World/Users/This/Is/An/Example/Bla.cs", "C:/Hello/World Users/This/Is/An/example/bla.cs", "C:/Hello/World-Users/This/Is/Not/An/Example/",]), "C:/Hello/World")
find the longest common prefix among a list of
inputs
. for efficiency, this function starts off by using the shortest string amonginputs
, then performs a binary search.Example