Skip to content

Instantly share code, notes, and snippets.

@DDDDDanica
Created January 4, 2017 11:31
Show Gist options
  • Save DDDDDanica/5e6b3fd7b894a3cbd077cf15dadd5de5 to your computer and use it in GitHub Desktop.
Save DDDDDanica/5e6b3fd7b894a3cbd077cf15dadd5de5 to your computer and use it in GitHub Desktop.
2016.12.20
//2016.12.20
//A. spread operator
//Allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables (for destructuring assignment) are expected.
//B. Find the longest word in the string which is passed in as a parameter.
function findLongest (str) {
const array = str.split(' ');
let longest = array.reduce((a, b)=> { return a.length > b.length ? a : b; });
return console.log("The longest word in '" + str + "' is: " + longest);
}
findLongest("never forget to empty your vacuum bags");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment