I want to find Longer Strings from this array:
const myArr = ["first", "second", "third", "fourth", "fifth", "sixth", "seven", "eighth"]
in this array "second","fourth","eighth" has length of 6. I want to return these in an array.
const myArr = ["first", "second", "third", "fourth", "fifth", "sixth", "seven", "eighth"]
function longerStrings(arr) {
let largeStrings = []
let longerWord = ''
for (let name of arr) {
if (name.length > longerWord.length) {
longerWord = name
largeStrings.push(longerWord)
}
}
return largeStrings
}
longerStrings(myArr)
expected output is: ["second","fourth","eighth"]
but returns =["first","second"]