diff --git a/MVC/box.html b/MVC/box.html new file mode 100644 index 0000000..dca6391 --- /dev/null +++ b/MVC/box.html @@ -0,0 +1,35 @@ + + + + + + MVC Skjemaer + + +
+ +
+ + + \ No newline at end of file diff --git a/MVC/meldingsbokser.html b/MVC/meldingsbokser.html new file mode 100644 index 0000000..ae17aa2 --- /dev/null +++ b/MVC/meldingsbokser.html @@ -0,0 +1,37 @@ + + + + + + + Document + + + +
+ +
+ + + + \ No newline at end of file diff --git a/MVC/skjemaer.html b/MVC/skjemaer.html index dca6391..ac0aac3 100644 --- a/MVC/skjemaer.html +++ b/MVC/skjemaer.html @@ -1,35 +1,109 @@ + - MVC Skjemaer + Document +
- +
+ \ No newline at end of file diff --git a/eloquentjavascript/data_structures.js b/eloquentjavascript/data_structures.js index 67111a0..441d48c 100644 --- a/eloquentjavascript/data_structures.js +++ b/eloquentjavascript/data_structures.js @@ -1,123 +1,123 @@ // Weresquirrel var JOURNAL = [ - {"events":["carrot","exercise","weekend"],"squirrel":false}, - {"events":["bread","pudding","brushed teeth","weekend","touched tree"],"squirrel":false}, - {"events":["carrot","nachos","brushed teeth","cycling","weekend"],"squirrel":false}, - {"events":["brussel sprouts","ice cream","brushed teeth","computer","weekend"],"squirrel":false}, - {"events":["potatoes","candy","brushed teeth","exercise","weekend","dentist"],"squirrel":false}, - {"events":["brussel sprouts","pudding","brushed teeth","running","weekend"],"squirrel":false}, - {"events":["pizza","brushed teeth","computer","work","touched tree"],"squirrel":false}, - {"events":["bread","beer","brushed teeth","cycling","work"],"squirrel":false}, - {"events":["cauliflower","brushed teeth","work"],"squirrel":false}, - {"events":["pizza","brushed teeth","cycling","work"],"squirrel":false}, - {"events":["lasagna","nachos","brushed teeth","work"],"squirrel":false}, - {"events":["brushed teeth","weekend","touched tree"],"squirrel":false}, - {"events":["lettuce","brushed teeth","television","weekend"],"squirrel":false}, - {"events":["spaghetti","brushed teeth","work"],"squirrel":false}, - {"events":["brushed teeth","computer","work"],"squirrel":false}, - {"events":["lettuce","nachos","brushed teeth","work"],"squirrel":false}, - {"events":["carrot","brushed teeth","running","work"],"squirrel":false}, - {"events":["brushed teeth","work"],"squirrel":false}, - {"events":["cauliflower","reading","weekend"],"squirrel":false}, - {"events":["bread","brushed teeth","weekend"],"squirrel":false}, - {"events":["lasagna","brushed teeth","exercise","work"],"squirrel":false}, - {"events":["spaghetti","brushed teeth","reading","work"],"squirrel":false}, - {"events":["carrot","ice cream","brushed teeth","television","work"],"squirrel":false}, - {"events":["spaghetti","nachos","work"],"squirrel":false}, - {"events":["cauliflower","ice cream","brushed teeth","cycling","work"],"squirrel":false}, - {"events":["spaghetti","peanuts","computer","weekend"],"squirrel":true}, - {"events":["potatoes","ice cream","brushed teeth","computer","weekend"],"squirrel":false}, - {"events":["potatoes","ice cream","brushed teeth","work"],"squirrel":false}, - {"events":["peanuts","brushed teeth","running","work"],"squirrel":false}, - {"events":["potatoes","exercise","work"],"squirrel":false}, - {"events":["pizza","ice cream","computer","work"],"squirrel":false}, - {"events":["lasagna","ice cream","work"],"squirrel":false}, - {"events":["cauliflower","candy","reading","weekend"],"squirrel":false}, - {"events":["lasagna","nachos","brushed teeth","running","weekend"],"squirrel":false}, - {"events":["potatoes","brushed teeth","work"],"squirrel":false}, - {"events":["carrot","work"],"squirrel":false}, - {"events":["pizza","beer","work","dentist"],"squirrel":false}, - {"events":["lasagna","pudding","cycling","work"],"squirrel":false}, - {"events":["spaghetti","brushed teeth","reading","work"],"squirrel":false}, - {"events":["spaghetti","pudding","television","weekend"],"squirrel":false}, - {"events":["bread","brushed teeth","exercise","weekend"],"squirrel":false}, - {"events":["lasagna","peanuts","work"],"squirrel":true}, - {"events":["pizza","work"],"squirrel":false}, - {"events":["potatoes","exercise","work"],"squirrel":false}, - {"events":["brushed teeth","exercise","work"],"squirrel":false}, - {"events":["spaghetti","brushed teeth","television","work"],"squirrel":false}, - {"events":["pizza","cycling","weekend"],"squirrel":false}, - {"events":["carrot","brushed teeth","weekend"],"squirrel":false}, - {"events":["carrot","beer","brushed teeth","work"],"squirrel":false}, - {"events":["pizza","peanuts","candy","work"],"squirrel":true}, - {"events":["carrot","peanuts","brushed teeth","reading","work"],"squirrel":false}, - {"events":["potatoes","peanuts","brushed teeth","work"],"squirrel":false}, - {"events":["carrot","nachos","brushed teeth","exercise","work"],"squirrel":false}, - {"events":["pizza","peanuts","brushed teeth","television","weekend"],"squirrel":false}, - {"events":["lasagna","brushed teeth","cycling","weekend"],"squirrel":false}, - {"events":["cauliflower","peanuts","brushed teeth","computer","work","touched tree"],"squirrel":false}, - {"events":["lettuce","brushed teeth","television","work"],"squirrel":false}, - {"events":["potatoes","brushed teeth","computer","work"],"squirrel":false}, - {"events":["bread","candy","work"],"squirrel":false}, - {"events":["potatoes","nachos","work"],"squirrel":false}, - {"events":["carrot","pudding","brushed teeth","weekend"],"squirrel":false}, - {"events":["carrot","brushed teeth","exercise","weekend","touched tree"],"squirrel":false}, - {"events":["brussel sprouts","running","work"],"squirrel":false}, - {"events":["brushed teeth","work"],"squirrel":false}, - {"events":["lettuce","brushed teeth","running","work"],"squirrel":false}, - {"events":["candy","brushed teeth","work"],"squirrel":false}, - {"events":["brussel sprouts","brushed teeth","computer","work"],"squirrel":false}, - {"events":["bread","brushed teeth","weekend"],"squirrel":false}, - {"events":["cauliflower","brushed teeth","weekend"],"squirrel":false}, - {"events":["spaghetti","candy","television","work","touched tree"],"squirrel":false}, - {"events":["carrot","pudding","brushed teeth","work"],"squirrel":false}, - {"events":["lettuce","brushed teeth","work"],"squirrel":false}, - {"events":["carrot","ice cream","brushed teeth","cycling","work"],"squirrel":false}, - {"events":["pizza","brushed teeth","work"],"squirrel":false}, - {"events":["spaghetti","peanuts","exercise","weekend"],"squirrel":true}, - {"events":["bread","beer","computer","weekend","touched tree"],"squirrel":false}, - {"events":["brushed teeth","running","work"],"squirrel":false}, - {"events":["lettuce","peanuts","brushed teeth","work","touched tree"],"squirrel":false}, - {"events":["lasagna","brushed teeth","television","work"],"squirrel":false}, - {"events":["cauliflower","brushed teeth","running","work"],"squirrel":false}, - {"events":["carrot","brushed teeth","running","work"],"squirrel":false}, - {"events":["carrot","reading","weekend"],"squirrel":false}, - {"events":["carrot","peanuts","reading","weekend"],"squirrel":true}, - {"events":["potatoes","brushed teeth","running","work"],"squirrel":false}, - {"events":["lasagna","ice cream","work","touched tree"],"squirrel":false}, - {"events":["cauliflower","peanuts","brushed teeth","cycling","work"],"squirrel":false}, - {"events":["pizza","brushed teeth","running","work"],"squirrel":false}, - {"events":["lettuce","brushed teeth","work"],"squirrel":false}, - {"events":["bread","brushed teeth","television","weekend"],"squirrel":false}, - {"events":["cauliflower","peanuts","brushed teeth","weekend"],"squirrel":false} - ]; + { "events": ["carrot", "exercise", "weekend"], "squirrel": false }, + { "events": ["bread", "pudding", "brushed teeth", "weekend", "touched tree"], "squirrel": false }, + { "events": ["carrot", "nachos", "brushed teeth", "cycling", "weekend"], "squirrel": false }, + { "events": ["brussel sprouts", "ice cream", "brushed teeth", "computer", "weekend"], "squirrel": false }, + { "events": ["potatoes", "candy", "brushed teeth", "exercise", "weekend", "dentist"], "squirrel": false }, + { "events": ["brussel sprouts", "pudding", "brushed teeth", "running", "weekend"], "squirrel": false }, + { "events": ["pizza", "brushed teeth", "computer", "work", "touched tree"], "squirrel": false }, + { "events": ["bread", "beer", "brushed teeth", "cycling", "work"], "squirrel": false }, + { "events": ["cauliflower", "brushed teeth", "work"], "squirrel": false }, + { "events": ["pizza", "brushed teeth", "cycling", "work"], "squirrel": false }, + { "events": ["lasagna", "nachos", "brushed teeth", "work"], "squirrel": false }, + { "events": ["brushed teeth", "weekend", "touched tree"], "squirrel": false }, + { "events": ["lettuce", "brushed teeth", "television", "weekend"], "squirrel": false }, + { "events": ["spaghetti", "brushed teeth", "work"], "squirrel": false }, + { "events": ["brushed teeth", "computer", "work"], "squirrel": false }, + { "events": ["lettuce", "nachos", "brushed teeth", "work"], "squirrel": false }, + { "events": ["carrot", "brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["brushed teeth", "work"], "squirrel": false }, + { "events": ["cauliflower", "reading", "weekend"], "squirrel": false }, + { "events": ["bread", "brushed teeth", "weekend"], "squirrel": false }, + { "events": ["lasagna", "brushed teeth", "exercise", "work"], "squirrel": false }, + { "events": ["spaghetti", "brushed teeth", "reading", "work"], "squirrel": false }, + { "events": ["carrot", "ice cream", "brushed teeth", "television", "work"], "squirrel": false }, + { "events": ["spaghetti", "nachos", "work"], "squirrel": false }, + { "events": ["cauliflower", "ice cream", "brushed teeth", "cycling", "work"], "squirrel": false }, + { "events": ["spaghetti", "peanuts", "computer", "weekend"], "squirrel": true }, + { "events": ["potatoes", "ice cream", "brushed teeth", "computer", "weekend"], "squirrel": false }, + { "events": ["potatoes", "ice cream", "brushed teeth", "work"], "squirrel": false }, + { "events": ["peanuts", "brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["potatoes", "exercise", "work"], "squirrel": false }, + { "events": ["pizza", "ice cream", "computer", "work"], "squirrel": false }, + { "events": ["lasagna", "ice cream", "work"], "squirrel": false }, + { "events": ["cauliflower", "candy", "reading", "weekend"], "squirrel": false }, + { "events": ["lasagna", "nachos", "brushed teeth", "running", "weekend"], "squirrel": false }, + { "events": ["potatoes", "brushed teeth", "work"], "squirrel": false }, + { "events": ["carrot", "work"], "squirrel": false }, + { "events": ["pizza", "beer", "work", "dentist"], "squirrel": false }, + { "events": ["lasagna", "pudding", "cycling", "work"], "squirrel": false }, + { "events": ["spaghetti", "brushed teeth", "reading", "work"], "squirrel": false }, + { "events": ["spaghetti", "pudding", "television", "weekend"], "squirrel": false }, + { "events": ["bread", "brushed teeth", "exercise", "weekend"], "squirrel": false }, + { "events": ["lasagna", "peanuts", "work"], "squirrel": true }, + { "events": ["pizza", "work"], "squirrel": false }, + { "events": ["potatoes", "exercise", "work"], "squirrel": false }, + { "events": ["brushed teeth", "exercise", "work"], "squirrel": false }, + { "events": ["spaghetti", "brushed teeth", "television", "work"], "squirrel": false }, + { "events": ["pizza", "cycling", "weekend"], "squirrel": false }, + { "events": ["carrot", "brushed teeth", "weekend"], "squirrel": false }, + { "events": ["carrot", "beer", "brushed teeth", "work"], "squirrel": false }, + { "events": ["pizza", "peanuts", "candy", "work"], "squirrel": true }, + { "events": ["carrot", "peanuts", "brushed teeth", "reading", "work"], "squirrel": false }, + { "events": ["potatoes", "peanuts", "brushed teeth", "work"], "squirrel": false }, + { "events": ["carrot", "nachos", "brushed teeth", "exercise", "work"], "squirrel": false }, + { "events": ["pizza", "peanuts", "brushed teeth", "television", "weekend"], "squirrel": false }, + { "events": ["lasagna", "brushed teeth", "cycling", "weekend"], "squirrel": false }, + { "events": ["cauliflower", "peanuts", "brushed teeth", "computer", "work", "touched tree"], "squirrel": false }, + { "events": ["lettuce", "brushed teeth", "television", "work"], "squirrel": false }, + { "events": ["potatoes", "brushed teeth", "computer", "work"], "squirrel": false }, + { "events": ["bread", "candy", "work"], "squirrel": false }, + { "events": ["potatoes", "nachos", "work"], "squirrel": false }, + { "events": ["carrot", "pudding", "brushed teeth", "weekend"], "squirrel": false }, + { "events": ["carrot", "brushed teeth", "exercise", "weekend", "touched tree"], "squirrel": false }, + { "events": ["brussel sprouts", "running", "work"], "squirrel": false }, + { "events": ["brushed teeth", "work"], "squirrel": false }, + { "events": ["lettuce", "brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["candy", "brushed teeth", "work"], "squirrel": false }, + { "events": ["brussel sprouts", "brushed teeth", "computer", "work"], "squirrel": false }, + { "events": ["bread", "brushed teeth", "weekend"], "squirrel": false }, + { "events": ["cauliflower", "brushed teeth", "weekend"], "squirrel": false }, + { "events": ["spaghetti", "candy", "television", "work", "touched tree"], "squirrel": false }, + { "events": ["carrot", "pudding", "brushed teeth", "work"], "squirrel": false }, + { "events": ["lettuce", "brushed teeth", "work"], "squirrel": false }, + { "events": ["carrot", "ice cream", "brushed teeth", "cycling", "work"], "squirrel": false }, + { "events": ["pizza", "brushed teeth", "work"], "squirrel": false }, + { "events": ["spaghetti", "peanuts", "exercise", "weekend"], "squirrel": true }, + { "events": ["bread", "beer", "computer", "weekend", "touched tree"], "squirrel": false }, + { "events": ["brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["lettuce", "peanuts", "brushed teeth", "work", "touched tree"], "squirrel": false }, + { "events": ["lasagna", "brushed teeth", "television", "work"], "squirrel": false }, + { "events": ["cauliflower", "brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["carrot", "brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["carrot", "reading", "weekend"], "squirrel": false }, + { "events": ["carrot", "peanuts", "reading", "weekend"], "squirrel": true }, + { "events": ["potatoes", "brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["lasagna", "ice cream", "work", "touched tree"], "squirrel": false }, + { "events": ["cauliflower", "peanuts", "brushed teeth", "cycling", "work"], "squirrel": false }, + { "events": ["pizza", "brushed teeth", "running", "work"], "squirrel": false }, + { "events": ["lettuce", "brushed teeth", "work"], "squirrel": false }, + { "events": ["bread", "brushed teeth", "television", "weekend"], "squirrel": false }, + { "events": ["cauliflower", "peanuts", "brushed teeth", "weekend"], "squirrel": false } +]; function tableFor(event, journal) { - let table = [0,0,0,0]; - for (let i = 0; i < journal.length; i++) { - let entry = journal[i], index = 0; - if (entry.events.includes(event)) index += 1; - if (entry.squirrel) index += 2; - table[index] += 1; - } - return table; + let table = [0, 0, 0, 0]; + for (let i = 0; i < journal.length; i++) { + let entry = journal[i], index = 0; + if (entry.events.includes(event)) index += 1; + if (entry.squirrel) index += 2; + table[index] += 1; } + return table; +} console.log(tableFor("pizza", JOURNAL)); function phi(table) { - return (table[3] * table[0] - table[2] * table[1]) / Math.sqrt( - (table[2] + table[3]) * - (table[0] + table[1]) * - (table[1] + table[3]) * - (table[0] + table[2])); + return (table[3] * table[0] - table[2] * table[1]) / Math.sqrt( + (table[2] + table[3]) * + (table[0] + table[1]) * + (table[1] + table[3]) * + (table[0] + table[2])); }; -function journalEvents(journal){ +function journalEvents(journal) { let events = []; - for (let entry of journal){ - for (let event of entry.events){ - if (!events.includes(event)){ + for (let entry of journal) { + for (let event of entry.events) { + if (!events.includes(event)) { events.push(event); } } @@ -126,9 +126,17 @@ function journalEvents(journal){ } console.log(journalEvents(JOURNAL)); -for (let event of journalEvents(JOURNAL)){ +for (let event of journalEvents(JOURNAL)) { let correlation = phi(tableFor(event, JOURNAL)); - if (correlation > 0.1 || correlation < -0.1){ + if (correlation > 0.1 || correlation < -0.1) { console.log(event + ":", correlation) - } + } } + +for (let entry of JOURNAL) { + if (entry.events.includes("peanuts") && + !entry.events.includes("brushed teeth")) { + entry.events.push('peanut teeth'); + } +} +console.log(phi(tableFor("peanut teeth", JOURNAL))); diff --git a/eloquentjavascript/todolist.js b/eloquentjavascript/todolist.js new file mode 100644 index 0000000..9f4d87b --- /dev/null +++ b/eloquentjavascript/todolist.js @@ -0,0 +1,50 @@ +let todoList = []; + +function remember(task) { + todoList.push(task) +} +function getTask() { + return todoList.shift(); +} +function rememberUrgently(task) { + todoList.unshift(task) +} + +// remember("groceries"); +// remember("sleep"); +// console.log(todoList); +// console.log(getTask()); +// rememberUrgently("eat"); +// remember("run"); +// console.log(todoList); +// console.log(todoList.indexOf(2)); + +function remove(array, index) { + return array.slice(0, index) + .concat(array.slice(index + 1)); +} +// console.log(remove(["a", "b", "c", "d", "e"], 2)); + +let sentence = "Secretarybirds specialize in stomping"; +let words = sentence.split(" "); +// console.log(words); +// console.log(words.join(". ")); + +function max(...numbers) { + let result = -Infinity; + for (let number of numbers) { + if (number > result) result = number; + } + return result; +} +let numbers = [4, 1, 9, -22, 14, 69, 1337]; +console.log(max(...numbers)); + +function randomPointOnCircle(radius) { + let angle = Math.random() * 2 * Math.PI; + return { + x: radius * Math.cos(angle), + y: radius * Math.sin(angle) + }; +} +console.log(randomPointOnCircle(2));