Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Created May 3, 2017 22:39
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 glinesbdev/97cdc48600d3368252703e6befdf745f to your computer and use it in GitHub Desktop.
Save glinesbdev/97cdc48600d3368252703e6befdf745f to your computer and use it in GitHub Desktop.
Longest word in string (immutable.js)
<!doctype html>
<html>
<head>
<title>Immutable</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.min.js"></script>
<script>
const lyrics = "Another dream that will never come true Just to compliment your sorrow Another life that I've taken from you A gift to add on to your pain and suffering Another truth you can never believe Has crippled you completely All the cries you're beginning to hear Trapped in your mind, and the sound is deafening Let me enlighten you This is the way I pray Living just isn't hard enough Burn me alive, inside Living my life's not hard enough Take everything away Another nightmare about to come true Will manifest tomorrow Another love that I've taken from you Lost in time, on the edge of suffering Another taste of the evil I breed Will level you completely Bring to life everything that you fear Live in the dark, and the world is threatening Let me enlighten you This is the way i pray Living just isn't hard enough Burn me alive, inside Living my life's not hard enough Take everything away Return to me Leave me no one Turn to me Return to me Cast aside You've made me turn away Living just isn't hard enough Burn me alive, inside Living my life's not hard enough Take everything away";
const splitWords = lyrics.split(" ");
const wordsList = Immutable.List(splitWords);
const words = wordsList
.filter(x => x !== "")
.map(x => x.replace(/,/g, ""))
.map(x => x.replace(/\r?\n|\r/g, ""))
.map(x => x);
const longestWord2 = words.reduce((longest, word) => word.length > longest.length ? word : longest, "");
console.log(longestWord2);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment