Skip to content

Instantly share code, notes, and snippets.

@AminBusiness
Created November 9, 2018 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AminBusiness/241d4e1b081a1968aed1be66afe4dd3d to your computer and use it in GitHub Desktop.
Save AminBusiness/241d4e1b081a1968aed1be66afe4dd3d to your computer and use it in GitHub Desktop.
<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>
//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