From ca7b2ad5d9a793433dba6ed9100cd49a4006fd0b Mon Sep 17 00:00:00 2001 From: Lucas Thenert Date: Fri, 27 Jan 2023 12:24:43 +0100 Subject: [PATCH] Funktion Dreierpasch erstellt --- kniffel/inc/dreierPasch.js | 15 +++++++++++++++ kniffel/index.html | 1 + 2 files changed, 16 insertions(+) create mode 100644 kniffel/inc/dreierPasch.js diff --git a/kniffel/inc/dreierPasch.js b/kniffel/inc/dreierPasch.js new file mode 100644 index 0000000..d536c0e --- /dev/null +++ b/kniffel/inc/dreierPasch.js @@ -0,0 +1,15 @@ +function dreierPasch(wuerfelArr){ + let output = 0; + let countObj = {} + for(let x of wuerfelArr){ + countObj[x] = (countObj[x] || 0) + 1; + } + let vals = Object.values(countObj); + if(( vals[1] === 3) || (vals[0] === 3)|| (vals[2] === 3)){ + wuerfelArr.forEach(element => { + output += element; + }); + } + return output; + +} \ No newline at end of file diff --git a/kniffel/index.html b/kniffel/index.html index 2a2328f..fb64bd4 100644 --- a/kniffel/index.html +++ b/kniffel/index.html @@ -7,6 +7,7 @@ + Kniffel