longestCommonPrefix

import { longestCommonPrefix } from "jsr:@ende/text/unstable-longest-common-prefix";

function ยท experimental

function longestCommonPrefix(strs: ArrayLike<string>): string

Gets the longest common prefix of an array of strings.

strs: ArrayLike<string>

The array of strings to find the common prefix for.

Returns

The longest common prefix.

Example: Usage

import { longestCommonPrefix } from "@ende/text/unstable-longest-common-prefix";
import { assertEquals } from "@ende/assert";

assertEquals(longestCommonPrefix(["flower", "flow", "flight"]), "fl");

Source