Files
advent-of-code/script.js

33 lines
827 B
JavaScript

const ASSIGNMENT = 'assignment';
const ANSWER = 'answer';
const NEWLINE_CHARACTER = '\n';
/**
* Main function
*/
window.onload = function() {
document.getElementById(ASSIGNMENT).addEventListener("input", calculateAnswer);
}
/**
* Listener function for input in assignment field.
* @param event the onInput event
*/
function calculateAnswer(event) {
console.info("Calculating answer for input...");
let answer = algorithm(event.target.value, TOP_N);
document.getElementById(ANSWER).innerText = answer;
}
/**
* Calculate the answer to assignment.
* @param assignment the input from the assignment.
* @return string the answer
*/
function algorithm(assignment) {
let lines = assignment.trim().split(NEWLINE_CHARACTER);
console.info("Linecount:" + lines.length);
// TODO: implement assignment
}