var longestCommonPrefix = function(strs) {
var word = "";
for (var i = 0; i < strs.length; i++) {
var firstWord = strs[i];
var secondWord = strs[1 + i];
if (strs[i].length >= secondWord.length) {
for (var d = 0; d < strs[i].length; d++) {
var store1 = firstWord[d];
if (secondWord.indexOf(store1) != -1) {
word += store1;
} else {
word = "";
}
}
} else {
for (var f = 0; f < strs[i + 1].length; f++) {
var store2 = firstWord[f];
if (firstWord.indexOf(store1) != -1) {
word += store2;
} else {
word = "";
}
}
}
}
return (word);
};
I am trying to check the characters of two words in an array and store it in.
Issue, my secondWord is not able to grab the second element of array strs