Created
January 1, 2017 20:54
-
-
Save ishanray/6c1036a0717d9d7323b1d786de00c65c to your computer and use it in GitHub Desktop.
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
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