Skip to content

Instantly share code, notes, and snippets.

@willwashburn
Last active December 17, 2015 01:29
Show Gist options
  • Save willwashburn/5529120 to your computer and use it in GitHub Desktop.
Save willwashburn/5529120 to your computer and use it in GitHub Desktop.
Booker.com interview quesiton
<html>
<head>
<title>Booker.com Project | Will Washburn</title>
<script type="text/javascript">
var quotedText = "Anyway, I keep picturing all these little kids playing some game in this big field of rye and all. Thousands of little kids, and nobody's around - nobody big, I mean - except me. And I'm standing on the edge of some crazy cliff. What I have to do, I have to catch everybody if they start to go over the cliff - I mean if they're running and they don't look where they're going I have to come out from somewhere and catch them. That's all I do all day. I'd just be the catcher in the rye and all. I know it's crazy, but that's the only thing I'd really like to be wombatman. ";
var cleanText = quotedText
.replace(/[^A-z ']/g,"")
.toLowerCase()
.trim();
var words = {};
var wordsList = cleanText.split(" ");
for(i=0;i<wordsList.length;i++) {
if(wordsList[i] != '') {
if(words[wordsList[i]]) {
words[wordsList[i]]++;
} else {
words[wordsList[i]] = 1;
}
}
}
for (var word in words){
if (typeof words[word] !== 'function') {
document.write(word + '['+ words[word] + '] <br />\n');
}
}
</script>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment