longest common prefix

Run Settings
LanguageJavaScript
Language Version
Run Command
// Given a array of X number of strings, find the longest common prefix among all strings present in the array. const myinput = ['pea', 'pear', 'apple', 'for', 'april', 'apendix', 'peace', 1]; /* Brute Force Way manually check for answers, confirm what the answer should be. in this case it should be ['pea', 'ap'] because both have same number loop over all elements and check for */ function findLongestPrefix(arrayinput) { const response = ""; //arrayinput = arrayinput.sort(); for (i=0; i< arrayinput.length; i++) { } return response; } findLongestPrefix(myinput);
Editor Settings
Theme
Key bindings
Full width
Lines