Skip to content

Instantly share code, notes, and snippets.

@rich-97
Created November 10, 2016 19:10
Show Gist options
  • Save rich-97/b68a12559ec81a08c6454be2959fd87e to your computer and use it in GitHub Desktop.
Save rich-97/b68a12559ec81a08c6454be2959fd87e to your computer and use it in GitHub Desktop.
the longest word in javascript
'use strict';
const str = 'example example2 proof guide';
const arr = str.split(' ');
const arrLength = [];
for (let i of arr) arrLength.push(i.length);
const max = Math.max.apply(null, arrLength);
for (let i = 0; i < arr.length; i++) {
if (max === arr[i].length) console.log(arr[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment