Skip to content

Commit 8c48351

Browse files
committed
Improve colors
1 parent 17c22f5 commit 8c48351

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

nodejs-assets/nodejs-project/index.html

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,37 @@
416416

417417
return indices;
418418
}
419+
function getIndicesOfNextLargestNumbers(arr) {
420+
if (!arr || arr.length === 0) {
421+
return [];
422+
}
423+
424+
const largestIndices = getIndicesOfLargestNumbers(arr);
425+
const largestNumber = arr[largestIndices[0]]; // Get the actual largest number
426+
427+
const nextLargestIndices = [];
428+
let nextLargestNumber = -Infinity; // Initialize to negative infinity
429+
430+
for (let i = 0; i < arr.length; i++) {
431+
if (
432+
i !== largestIndices[0] &&
433+
arr[i] > nextLargestNumber &&
434+
!largestIndices.includes(i)
435+
) {
436+
nextLargestNumber = arr[i];
437+
nextLargestIndices.length = 0; // Clear the indices array
438+
nextLargestIndices.push(i);
439+
} else if (
440+
i !== largestIndices[0] &&
441+
arr[i] === nextLargestNumber &&
442+
!largestIndices.includes(i)
443+
) {
444+
nextLargestIndices.push(i);
445+
}
446+
}
447+
448+
return nextLargestIndices;
449+
}
419450
function getIndicesOfSmallestNumbers(arr) {
420451
if (!arr || arr.length === 0) {
421452
return []; // Handle empty or null array
@@ -512,6 +543,7 @@
512543

513544
const indicesOfHigh = getIndicesOfLargestNumbers(cellVolts);
514545
const indicesOfLow = getIndicesOfSmallestNumbers(cellVolts);
546+
const indicesOfNextHigh = getIndicesOfNextLargestNumbers(cellVolts);
515547
let highVoltageIndex = indicesOfHigh.length === 1 ? indicesOfHigh[0] : -1;
516548
let lowVoltageIndex = indicesOfLow.length === 1 ? indicesOfLow[0] : -1;
517549

@@ -634,13 +666,15 @@
634666
635667
const isHigh = indicesOfHigh.includes(i);
636668
const isLow = indicesOfLow.includes(i);
669+
const isNextHigh = indicesOfNextHigh.includes(i);
637670
671+
if (isNextHigh) {
672+
return '🔵';
673+
}
638674
if (isHigh) {
639675
return '🟢';
640676
}
641-
if (isLow) {
642-
return '🔴';
643-
}
677+
644678
return off;
645679
})()}
646680
</span>

0 commit comments

Comments
 (0)