Use reduce to find smallest and largest inputNums.

Tab shadows are now displayed using css classes
This commit is contained in:
j433866 2019-07-03 16:05:20 +01:00
parent b3fa1eaae2
commit 30a66f1441
3 changed files with 24 additions and 27 deletions

View File

@ -153,6 +153,14 @@
width: fit-content; width: fit-content;
} }
.tabs-left > li:first-child {
box-shadow: 15px 0px 15px -15px var(--primary-border-colour) inset;
}
.tabs-right > li:last-child {
box-shadow: -15px 0px 15px -15px var(--primary-border-colour) inset;
}
#input-wrapper, #input-wrapper,
#output-wrapper, #output-wrapper,
#input-wrapper > * , #input-wrapper > * ,

View File

@ -251,23 +251,16 @@ class TabWaiter {
tabsList.appendChild(this.createTabElement(nums[i], active, io)); tabsList.appendChild(this.createTabElement(nums[i], active, io));
} }
const firstTab = tabsList.firstElementChild,
lastTab = tabsList.lastElementChild;
// Display shadows if there are tabs left / right of the displayed tabs // Display shadows if there are tabs left / right of the displayed tabs
if (firstTab) { if (tabsLeft) {
if (tabsLeft) { tabsList.classList.add("tabs-left");
firstTab.style.boxShadow = "15px 0px 15px -15px var(--primary-border-colour) inset"; } else {
} else { tabsList.classList.remove("tabs-left");
firstTab.style.boxShadow = "";
}
} }
if (lastTab) { if (tabsRight) {
if (tabsRight) { tabsList.classList.add("tabs-right");
lastTab.style.boxShadow = "-15px 0px 15px -15px var(--primary-border-colour) inset"; } else {
} else { tabsList.classList.remove("tabs-right");
lastTab.style.boxShadow = "";
}
} }
// Show or hide the tab bar depending on how many tabs we have // Show or hide the tab bar depending on how many tabs we have

View File

@ -315,13 +315,10 @@ self.getInputProgress = function(inputNum) {
* @returns {number} * @returns {number}
*/ */
self.getLargestInputNum = function(inputNums) { self.getLargestInputNum = function(inputNums) {
let max = -1; return inputNums.reduce((acc, val) => {
for (let i = 0; i < inputNums.length; i++) { val = parseInt(val, 10);
// Object.keys() returns a string array, so parseInt here return val > acc ? val : acc;
const num = parseInt(inputNums[i], 10); }, -1);
if (num > max) max = num;
}
return max;
}; };
/** /**
@ -331,11 +328,10 @@ self.getLargestInputNum = function(inputNums) {
* @returns {number} * @returns {number}
*/ */
self.getSmallestInputNum = function(inputNums) { self.getSmallestInputNum = function(inputNums) {
let min = Number.MAX_SAFE_INTEGER; const min = inputNums.reduce((acc, val) => {
for (let i = 0; i < inputNums.length; i++) { val = parseInt(val, 10);
const num = parseInt(inputNums[i], 10); return val < acc ? val : acc;
if (num < min) min = num; }, Number.MAX_SAFE_INTEGER);
}
// Assume we don't have this many tabs! // Assume we don't have this many tabs!
if (min === Number.MAX_SAFE_INTEGER) return -1; if (min === Number.MAX_SAFE_INTEGER) return -1;