Skip to content

Instantly share code, notes, and snippets.

@TamaHills
Created July 9, 2019 15:05
Show Gist options
  • Select an option

  • Save TamaHills/c5c828ef157f033bb0b584580f15de50 to your computer and use it in GitHub Desktop.

Select an option

Save TamaHills/c5c828ef157f033bb0b584580f15de50 to your computer and use it in GitHub Desktop.
function longestString(strings) {
var longString = ''
strings.forEach((str => {
longString = str.length > longString.length ? str : longString
}))
return longString
}
const strings1 = ['short', 'really, really long!', 'medium'];
console.log(longestString(strings1)); // <--- 'really, really long!'
const strings2 = ['short', 'first long string!!', 'medium', 'abcdefghijklmnopqr'];
console.log(longestString(strings2)); // <--- 'first long string!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment