Created
November 9, 2018 02:32
-
-
Save AminBusiness/241d4e1b081a1968aed1be66afe4dd3d to your computer and use it in GitHub Desktop.
// source https://jsbin.com/gavovuh
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
<script id="jsbin-javascript"> | |
//Challenge 7: The longest Word | |
//Returns the longest word of a string | |
//If more than one longest word, put it into an array | |
//ex. longestword | |
function longestWord(sen) | |
{ | |
//Create filtered array | |
const wordArr = sen.toLowerCase().match(/[a-z0-9]+/g); | |
//Sort by length | |
const sorted = wordArr.sort(function(a,b) | |
{ | |
return b.length - a.length; | |
}); | |
// console.log(sorted); | |
//Returns first number in an array | |
//return sorted[0]; | |
//if multiple words, put into an array | |
const longestWordArr = sorted.filter(function(word) | |
{ | |
return word.length === sorted[0].length; | |
}); | |
console.log(longestWordArr); | |
} | |
function letterChanges(str) {} | |
// Call function | |
const output = longestWord('Helloooooo there, my name is Amin'); | |
console.log(output); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">//Challenge 7: The longest Word | |
//Returns the longest word of a string | |
//If more than one longest word, put it into an array | |
//ex. longestword | |
function longestWord(sen) | |
{ | |
//Create filtered array | |
const wordArr = sen.toLowerCase().match(/[a-z0-9]+/g); | |
//Sort by length | |
const sorted = wordArr.sort(function(a,b) | |
{ | |
return b.length - a.length; | |
}); | |
// console.log(sorted); | |
//Returns first number in an array | |
//return sorted[0]; | |
//if multiple words, put into an array | |
const longestWordArr = sorted.filter(function(word) | |
{ | |
return word.length === sorted[0].length; | |
}); | |
console.log(longestWordArr); | |
} | |
function letterChanges(str) {} | |
// Call function | |
const output = longestWord('Helloooooo there, my name is Amin'); | |
console.log(output);</script> |
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
//Challenge 7: The longest Word | |
//Returns the longest word of a string | |
//If more than one longest word, put it into an array | |
//ex. longestword | |
function longestWord(sen) | |
{ | |
//Create filtered array | |
const wordArr = sen.toLowerCase().match(/[a-z0-9]+/g); | |
//Sort by length | |
const sorted = wordArr.sort(function(a,b) | |
{ | |
return b.length - a.length; | |
}); | |
// console.log(sorted); | |
//Returns first number in an array | |
//return sorted[0]; | |
//if multiple words, put into an array | |
const longestWordArr = sorted.filter(function(word) | |
{ | |
return word.length === sorted[0].length; | |
}); | |
console.log(longestWordArr); | |
} | |
function letterChanges(str) {} | |
// Call function | |
const output = longestWord('Helloooooo there, my name is Amin'); | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment