some more of eloquent datastructures

This commit is contained in:
Geir Okkenhaug Jerstad 2024-08-26 14:39:13 +02:00
parent a759fef088
commit ec72ed57b9
2 changed files with 51 additions and 11 deletions

View file

@ -1,42 +1,64 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intro</title> <title>Intro</title>
</head> </head>
<body> <body>
<div class="group"> <div class="group">
<div>Hei jeg heter</div> <div>Hei jeg heter</div>
<div id="namediv">...her kommer et navn</div> <div id="namediv">...her kommer et navn<br></div>
</div> </div>
<div class="group"> <div class="group">
<div>Jeg bor i</div> <div>Jeg bor i</div>
<div id="placediv">..her kommer et sted</div> <div id="placediv">..her kommer et sted<br></div>
</div> </div>
<div class="group"> <div class="group">
<div>Min favorittmat er</div> <div>Min favorittmat er</div>
<div id="fooddiv">...her kommer en matrett</div> <div id="fooddiv">...her kommer en matrett<br></div>
</div> </div>
<button onclick="setFields()">Klikk her for å sett inn verdier</button> <button onclick="setFields()">Klikk her for å sett inn verdier</button>
Navn: <input type="text" onchange="setName(this.value)">
Sted: <input type="text" onchange="setPlace(this.value)">
Mat: <input type="text" onchange="setFood(this.value)">
<script> <script>
let name;
// Model
let fistName;
let place; let place;
let food; let food;
// View
function setFields(){ function setFields() {
document.getElementById("namediv").innerHTML = "Geir"; document.getElementById("namediv").innerHTML = fistName;
document.getElementById("placediv").innerHTML = "Kristiansand"; document.getElementById("placediv").innerHTML = place;
document.getElementById("fooddiv").innerHTML = "Pizza"; document.getElementById("fooddiv").innerHTML = food;
} }
// Controller
function setName(nameInput) {
firstName = nameInput;
setFields();
}
function setPlace(placeInput) {
place = placeInput;
setFields();
}
function setFood(foodInput) {
food = foodInput;
setFields();
}
</script> </script>
<style> <style>
.group{ .group {
display: flex; display: flex;
padding: 1px;
} }
</style> </style>
</body> </body>
</html> </html>

View file

@ -113,4 +113,22 @@ function phi(table) {
(table[1] + table[3]) * (table[1] + table[3]) *
(table[0] + table[2])); (table[0] + table[2]));
}; };
// console.log(phi([76, 9, 4, 1])); function journalEvents(journal){
let events = [];
for (let entry of journal){
for (let event of entry.events){
if (!events.includes(event)){
events.push(event);
}
}
}
return events;
}
console.log(journalEvents(JOURNAL));
for (let event of journalEvents(JOURNAL)){
let correlation = phi(tableFor(event, JOURNAL));
if (correlation > 0.1 || correlation < -0.1){
console.log(event + ":", correlation)
}
}