Skip to content

Instantly share code, notes, and snippets.

@Underdoge
Created February 25, 2017 23:09
Show Gist options
  • Save Underdoge/6a1e3e2e8261ab3f9aebb81ac8da44d3 to your computer and use it in GitHub Desktop.
Save Underdoge/6a1e3e2e8261ab3f9aebb81ac8da44d3 to your computer and use it in GitHub Desktop.
allLongestStrings
function allLongestStrings(inputArray) {
var result=[""];
var count=0;
for(var i=0;i<inputArray.length;i++){
if(inputArray[i].length>=result[result.length-1].length){
if(inputArray[i].length>result[result.length-1].length)
count=1;
else
count++
result.push(inputArray[i]);
}
}
return result.slice(result.length-count);;
}
@gustoliv
Copy link

gustoliv commented Feb 5, 2019

A shorter way:

`function allLongestStrings(inputArray) {

var longestSize = 0;

inputArray.map(str => {
    if (str.length > longestSize) longestSize = str.length;
    
})

return inputArray.filter(str => str.length === longestSize)

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment