Skip to content

Instantly share code, notes, and snippets.

@ishanray
Created January 1, 2017 20:54
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 ishanray/6c1036a0717d9d7323b1d786de00c65c to your computer and use it in GitHub Desktop.
Save ishanray/6c1036a0717d9d7323b1d786de00c65c to your computer and use it in GitHub Desktop.
var lines = input.split('\n');
var wordlist = lines[0];
var wordScoresDict = {};
wordlist.map(word => wordScoresDict[word.toLowerCase()] = 0);
var hotels = [];
for (var i = 0, l = lines.length; i < l; i++) {
if (i == 0) {
continue;
} else if (i % 2 == 0) {
hotels.push({
id: lines[i],
rating: lines[i+1]
});
}
}
hotels.forEach(hotel => {
var wordsInRating = hotel.rating.match(/\w+/g).map(word => word.toLowerCase());
wordsInRating.map(word => {
if(wordScoresDict.hasOwnProperty(word)) {
wordScoresDict[word]++
}
});
var score = 0;
for (var el in wordScoresDict) {
score += wordScoresDict[el]
wordScoresDict[el] = 0;
}
hotel.score = score;
})
hotels.sort(function (a, b) {
return b.score - a.score;
}).map(item => item.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment