From 83365a71b7a3624d3159c1b60217863678f0c957 Mon Sep 17 00:00:00 2001 From: AyushmanTripathy Date: Thu, 24 Mar 2022 15:49:00 +0530 Subject: [PATCH 1/3] Day 9 30/30 solution --- Day 9/binaryCalculator.css | 47 +++++++++++++++++-------------------- Day 9/binaryCalculator.js | 48 ++++++++++++++------------------------ Day 9/index.html | 40 ++++++++++++++++--------------- 3 files changed, 59 insertions(+), 76 deletions(-) diff --git a/Day 9/binaryCalculator.css b/Day 9/binaryCalculator.css index 32cc449..de0e61c 100644 --- a/Day 9/binaryCalculator.css +++ b/Day 9/binaryCalculator.css @@ -1,33 +1,28 @@ body { - width: 33%; + width: 33vw; } - #res { - background-color: lightgray; - border: solid; - height: 48px; - font-size: 20px; + border: solid; + background-color: lightgray; + height: 48px; + font-size: 20px; } - -#btn0, #btn1 { - background-color: lightgreen; - color: brown; +.bin { + background-color: lightgreen; + color: brown; } - -#btnClr, #btnEql { - background-color: darkgreen; - color: white; +.sysBtn { + background-color: darkgreen; + color: white; } - -#btnSum, #btnSub, #btnMul, #btnDiv { - background-color: black; - color: red; +.operators { + background-color: black; + color: red; +} +button { + width: 25%; + height: 36px; + font-size: 18px; + float: left; + margin: 0px; } - -.buttonClass { - width: 25%; - height: 36px; - font-size: 18px; - margin: 0px; - float: left; -} \ No newline at end of file diff --git a/Day 9/binaryCalculator.js b/Day 9/binaryCalculator.js index b633e58..afe6b99 100644 --- a/Day 9/binaryCalculator.js +++ b/Day 9/binaryCalculator.js @@ -1,33 +1,19 @@ +let res = document.getElementById("res"); +const reset = () => (res.innerHTML = ""); +const input = (a) => (res.innerHTML += a); -// On clicking either 0 or 1, add the corresponding text to the result inner html -// On clicking any operator, add that operator text to the result inner html -// On clicking button clear, clear the results field -// On clicking equals, evaluate the expression - -document.getElementById('btn0').addEventListener('click', function() -{ - document.getElementById('res').insertAdjacentHTML('beforeend', '0'); -}); - -document.getElementById('btn1').addEventListener('click', function() -{ - document.getElementById('res').insertAdjacentHTML('beforeend', '1'); -}); - -function operatorAction(eve) -{ - var btn = eve.target; - // Add the inner html for the operator buttons into the results field - document.getElementById('res').insertAdjacentHTML('beforeend', btn.innerHTML); +function render() { + let code = res.innerHTML; + if (!code) return; + const matches = code.match(/[0-1]+/g); + if (matches) { + for (const match of matches) + code = code.replace(match, parseInt(Number(match), 2)); + } + try { + eval(`code=(${code})`); + } catch (e) { + console.error(e); + } + res.innerHTML = Math.round(code).toString(2); } - -document.getElementById('btnSum').onclick = operatorAction; -document.getElementById('btnMul').onclick = operatorAction; -document.getElementById('btnDiv').onclick = operatorAction; -document.getElementById('btnSub').onclick = operatorAction; - -document.getElementById('btnClr').onclick = function() -{ - (document.getElementById('res').innerHTML) = ""; -}; - diff --git a/Day 9/index.html b/Day 9/index.html index abfb85a..4dad012 100644 --- a/Day 9/index.html +++ b/Day 9/index.html @@ -1,23 +1,25 @@ - - - - Binary Calculator - - -
-
- - - - - - - - -
- - + + + Binary Calculator + + + +
+
+ + + + + + + + + + +
+ + From ff441d80f6b0b54da9dbd25ddede710134bfdca6 Mon Sep 17 00:00:00 2001 From: Rahmat Date: Sun, 17 Apr 2022 23:00:16 +0700 Subject: [PATCH 2/3] Update: unique sorted array using `Set()` method --- Day 3/Arrays.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Day 3/Arrays.js b/Day 3/Arrays.js index 90aa9a0..ca91f4e 100644 --- a/Day 3/Arrays.js +++ b/Day 3/Arrays.js @@ -5,10 +5,7 @@ **/ function getSecondLargest(nums) { // Complete the function - var sorted_array = nums.sort(function (a,b) {return a - b;}); - var unique_sorted_array = sorted_array.filter(function(elem, index, self) { - return index === self.indexOf(elem); - }) - + const sorted_array = nums.sort((a,b) => a - b ); + const unique_sorted_array = [...new Set(sorted_array)]; return unique_sorted_array[unique_sorted_array.length - 2]; } \ No newline at end of file From 9f2b3fe7e484ca5273068ba268b0c4e9521ed9a7 Mon Sep 17 00:00:00 2001 From: Raleigh Littles Date: Tue, 18 Oct 2022 00:17:41 -0700 Subject: [PATCH 3/3] Added BMAC link --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5ab80e9..a1feb74 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # About Solutions to HackerRank's [10 Days of Javascript](https://www.hackerrank.com/domains/tutorials/10-days-of-javascript/) challenge. + +## Show thanks! + +If these solutions were helpful to you, please feel free to express your gratitude! + +Buy Me A Coffee