@oazmi/kitchensink - v0.9.13

    Function commonPrefix

    • 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.

      Parameters

      • inputs: string[]

      Returns string

      import { assertEquals as assertEq } from "jsr:@std/assert"

      assertEq(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/")

      assertEq(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/")

      assertEq(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")
    MMNEPVFCICPMFPCPTTAAATR