Skip to content

@std/txt longest common prefix #6731

Open
@lionel-rowe

Description

@lionel-rowe

Is your feature request related to a problem? Please describe.

Find the longest common prefix of multiple strings.

Describe the solution you'd like

declare function longestCommonPrefix(strs: ArrayLike<string>): string
assertEquals(longestCommonPrefix([]), '')
assertEquals(longestCommonPrefix(['']), '')
assertEquals(longestCommonPrefix(['flower', 'flow', 'flight']), 'fl')
assertEquals(longestCommonPrefix(['flower', 'glow', 'flight']), '')
assertEquals(longestCommonPrefix(['💩', '💫']), '')

Describe alternatives you've considered

Maybe an equivalent under collections for longest common prefixes of lists (array/ArrayLikes)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions