longestPrefix interview question solution

This is my attempt at solving the longestPrefix interview question from cassidoo's weekly newsletter.

This is my attempt at solving the longestPrefix interview question from cassidoo's weekly newsletter.


Question:

Write a function to find the longest common prefix string in an array of strings.

Example:

$ longestPrefix(["cranberry","crawfish","crap"])
$ "cra"

$ longestPrefix(["parrot", "poodle", "fish"])
$ ""

Solution (try using browsing from a laptop if it doesn't load anything):

Comments and suggestions are welcome.

Subscribe to Faisal.Software

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe