mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 14:11:02 +01:00
Use reduce to find smallest and largest inputNums.
Tab shadows are now displayed using css classes
This commit is contained in:
parent
b3fa1eaae2
commit
30a66f1441
@ -153,6 +153,14 @@
|
||||
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,
|
||||
#output-wrapper,
|
||||
#input-wrapper > * ,
|
||||
|
@ -251,23 +251,16 @@ class TabWaiter {
|
||||
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
|
||||
if (firstTab) {
|
||||
if (tabsLeft) {
|
||||
firstTab.style.boxShadow = "15px 0px 15px -15px var(--primary-border-colour) inset";
|
||||
} else {
|
||||
firstTab.style.boxShadow = "";
|
||||
}
|
||||
if (tabsLeft) {
|
||||
tabsList.classList.add("tabs-left");
|
||||
} else {
|
||||
tabsList.classList.remove("tabs-left");
|
||||
}
|
||||
if (lastTab) {
|
||||
if (tabsRight) {
|
||||
lastTab.style.boxShadow = "-15px 0px 15px -15px var(--primary-border-colour) inset";
|
||||
} else {
|
||||
lastTab.style.boxShadow = "";
|
||||
}
|
||||
if (tabsRight) {
|
||||
tabsList.classList.add("tabs-right");
|
||||
} else {
|
||||
tabsList.classList.remove("tabs-right");
|
||||
}
|
||||
|
||||
// Show or hide the tab bar depending on how many tabs we have
|
||||
|
@ -315,13 +315,10 @@ self.getInputProgress = function(inputNum) {
|
||||
* @returns {number}
|
||||
*/
|
||||
self.getLargestInputNum = function(inputNums) {
|
||||
let max = -1;
|
||||
for (let i = 0; i < inputNums.length; i++) {
|
||||
// Object.keys() returns a string array, so parseInt here
|
||||
const num = parseInt(inputNums[i], 10);
|
||||
if (num > max) max = num;
|
||||
}
|
||||
return max;
|
||||
return inputNums.reduce((acc, val) => {
|
||||
val = parseInt(val, 10);
|
||||
return val > acc ? val : acc;
|
||||
}, -1);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -331,11 +328,10 @@ self.getLargestInputNum = function(inputNums) {
|
||||
* @returns {number}
|
||||
*/
|
||||
self.getSmallestInputNum = function(inputNums) {
|
||||
let min = Number.MAX_SAFE_INTEGER;
|
||||
for (let i = 0; i < inputNums.length; i++) {
|
||||
const num = parseInt(inputNums[i], 10);
|
||||
if (num < min) min = num;
|
||||
}
|
||||
const min = inputNums.reduce((acc, val) => {
|
||||
val = parseInt(val, 10);
|
||||
return val < acc ? val : acc;
|
||||
}, Number.MAX_SAFE_INTEGER);
|
||||
|
||||
// Assume we don't have this many tabs!
|
||||
if (min === Number.MAX_SAFE_INTEGER) return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user