Created
December 17, 2015 18:32
-
-
Save tamzinblake/a00c58afed94ea481581 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fs = require('fs') | |
var parse_log = function (log) { | |
var userPages = {} | |
logLines = log.split(/\r?\n/) | |
logLines.forEach(function (logLine) { | |
logLineData = logLine.split(/, /) | |
var userId = logLineData[1] | |
var pageId = logLineData[2] | |
if (userId !== undefined && pageId !== undefined) { | |
if (!userPages[userId]) { | |
userPages[userId] = [] | |
} | |
userPages[userId].push(pageId) | |
} | |
}) | |
var paths = {} | |
var userIds = Object.keys(userPages) | |
userIds.forEach(function (userId) { | |
var userSession = userPages[userId] | |
for (var i = 0; userSession[i+2] !== undefined; i++) { | |
userPathId = userSession[i] + ',' + userSession[i+1] + ',' + userSession[i+2] | |
if (!paths[userPathId]) { | |
paths[userPathId] = 0 | |
} | |
paths[userPathId]++ | |
} | |
}) | |
return paths | |
} | |
var log = fs.readFileSync('./input1.txt', { | |
encoding: 'utf8' | |
}) | |
var paths = parse_log(log) | |
var best = 0 | |
var bestId | |
var pathIds = Object.keys(paths) | |
pathIds.forEach(function (pathId) { | |
if (paths[pathId] > best) { | |
best = paths[pathId] | |
bestId = pathId | |
} | |
}) | |
console.log(bestId, best) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment