From 9c6a2c4116da03de04e0799b1b616d290e686a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ku=C4=87mierz?= Date: Mon, 18 Aug 2025 11:12:02 +0200 Subject: [PATCH] Potion Class 101 --- 5981ff1daf72e8747d000091/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 5981ff1daf72e8747d000091/index.js diff --git a/5981ff1daf72e8747d000091/index.js b/5981ff1daf72e8747d000091/index.js new file mode 100644 index 0000000..2f56c21 --- /dev/null +++ b/5981ff1daf72e8747d000091/index.js @@ -0,0 +1,22 @@ + +class Potion { + constructor(color, volume) { + this.color = color; + this.volume = volume; + } + mix(that) { + const volume = this.volume+that.volume; + const color = []; + for (let i = 0; i < this.color.length; ++i) { + const a = this.color[i] * this.volume; + const b = that.color[i] * that.volume; + color[i] = Math.ceil((a + b) / volume); + } + return new Potion(color, volume); + } +} + +const p1 = new Potion([255, 255, 255], 7); +const p2 = new Potion([ 51, 102, 51], 12); + +p1.mix(p2);