|
416 | 416 |
|
417 | 417 | return indices; |
418 | 418 | } |
| 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 | + } |
419 | 450 | function getIndicesOfSmallestNumbers(arr) { |
420 | 451 | if (!arr || arr.length === 0) { |
421 | 452 | return []; // Handle empty or null array |
|
512 | 543 |
|
513 | 544 | const indicesOfHigh = getIndicesOfLargestNumbers(cellVolts); |
514 | 545 | const indicesOfLow = getIndicesOfSmallestNumbers(cellVolts); |
| 546 | + const indicesOfNextHigh = getIndicesOfNextLargestNumbers(cellVolts); |
515 | 547 | let highVoltageIndex = indicesOfHigh.length === 1 ? indicesOfHigh[0] : -1; |
516 | 548 | let lowVoltageIndex = indicesOfLow.length === 1 ? indicesOfLow[0] : -1; |
517 | 549 |
|
|
634 | 666 |
|
635 | 667 | const isHigh = indicesOfHigh.includes(i); |
636 | 668 | const isLow = indicesOfLow.includes(i); |
| 669 | + const isNextHigh = indicesOfNextHigh.includes(i); |
637 | 670 |
|
| 671 | + if (isNextHigh) { |
| 672 | + return '🔵'; |
| 673 | + } |
638 | 674 | if (isHigh) { |
639 | 675 | return '🟢'; |
640 | 676 | } |
641 | | - if (isLow) { |
642 | | - return '🔴'; |
643 | | - } |
| 677 | +
|
644 | 678 | return off; |
645 | 679 | })()} |
646 | 680 | </span> |
|
0 commit comments