summaryrefslogtreecommitdiffhomepage
path: root/assets/js
diff options
context:
space:
mode:
authorMarvin Borner2019-03-21 16:03:27 +0100
committerMarvin Borner2019-03-21 16:03:27 +0100
commitafcf3ff1b101452a0d3b8607913d3564a2bad53b (patch)
treea4f3ccc3d04230e4988c1ef32a1937b3b36e9b26 /assets/js
parent815701fcf79904f24a7fd55aa045512e270ca55a (diff)
Added matrix merging
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/generator.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/assets/js/generator.js b/assets/js/generator.js
index ccdf02c..0de01d5 100644
--- a/assets/js/generator.js
+++ b/assets/js/generator.js
@@ -1,11 +1,18 @@
+// declare button event
document.getElementById('minify').onclick = () => {
+ // declare variables
let a, b, c, d;
+ let matrix = [[], [], [], []];
+
+ // replace input so it matches js boolean operators
const input = document.getElementById('input').value.replace(/#/g, '||').replace(/&/g, '&&');
+ // some logging..
document.getElementById('log').innerText = '';
document.getElementById('log').append('LOG\ndcba Z ID\n');
try {
+ // fill kv diagram
for (let i = 0; i < 16; i++) {
const currentBinary = (i >>> 0).toString(2);
// fill binary number with leading zeros until it is 4 digits long
@@ -17,6 +24,14 @@ document.getElementById('minify').onclick = () => {
document.getElementById('log').append(`${filledBinary} ${eval(input) ? '1' : '0'} ${document.getElementById(i + 1).getAttribute('data-id')}\n`);
document.getElementById(i + 1).innerText = eval(input) ? '1' : '0';
}
+
+ // merge grid with matrix (2D array)
+ document.querySelectorAll('[data-id]').forEach(element => {
+ let rowNumber = (element.getAttribute('data-id') / 4 - 0.1).toString();
+ rowNumber = rowNumber.substring(0, rowNumber.indexOf('.'));
+ matrix[rowNumber].push(parseInt(element.innerText, 2));
+ });
+ console.log(matrix);
} catch (err) {
console.error(err);
alert('Oh, da ist wohl was schiefgelaufen, bitte probieren Sie es noch einmal :)');