A Pen by Danica Shen on CodePen.
Created
January 4, 2017 11:31
-
-
Save DDDDDanica/5e6b3fd7b894a3cbd077cf15dadd5de5 to your computer and use it in GitHub Desktop.
2016.12.20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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