merge: FindSecondLargestElement: Support negative numbers (#1036)

* FindSecondLargestElement: Support negative numbers

* Updated Documentation in README.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Lars Müller
2022-06-03 19:07:49 +02:00
committed by GitHub
parent 0dccd280f3
commit dbffac253d
2 changed files with 5 additions and 1 deletions

View File

@ -142,6 +142,7 @@
* [BinaryExponentiationRecursive](Maths/BinaryExponentiationRecursive.js) * [BinaryExponentiationRecursive](Maths/BinaryExponentiationRecursive.js)
* [BisectionMethod](Maths/BisectionMethod.js) * [BisectionMethod](Maths/BisectionMethod.js)
* [CheckKishnamurthyNumber](Maths/CheckKishnamurthyNumber.js) * [CheckKishnamurthyNumber](Maths/CheckKishnamurthyNumber.js)
* [CollatzSequence](Maths/CollatzSequence.js)
* [Coordinate](Maths/Coordinate.js) * [Coordinate](Maths/Coordinate.js)
* [CoPrimeCheck](Maths/CoPrimeCheck.js) * [CoPrimeCheck](Maths/CoPrimeCheck.js)
* [DecimalExpansion](Maths/DecimalExpansion.js) * [DecimalExpansion](Maths/DecimalExpansion.js)
@ -159,6 +160,7 @@
* [FigurateNumber](Maths/FigurateNumber.js) * [FigurateNumber](Maths/FigurateNumber.js)
* [FindHcf](Maths/FindHcf.js) * [FindHcf](Maths/FindHcf.js)
* [FindLcm](Maths/FindLcm.js) * [FindLcm](Maths/FindLcm.js)
* [FindMaxRecursion](Maths/FindMaxRecursion.js)
* [FindMin](Maths/FindMin.js) * [FindMin](Maths/FindMin.js)
* [FindMinIterator](Maths/FindMinIterator.js) * [FindMinIterator](Maths/FindMinIterator.js)
* [GetEuclidGCD](Maths/GetEuclidGCD.js) * [GetEuclidGCD](Maths/GetEuclidGCD.js)
@ -166,6 +168,7 @@
* [IsDivisible](Maths/IsDivisible.js) * [IsDivisible](Maths/IsDivisible.js)
* [IsEven](Maths/IsEven.js) * [IsEven](Maths/IsEven.js)
* [IsOdd](Maths/IsOdd.js) * [IsOdd](Maths/IsOdd.js)
* [IsPronic](Maths/IsPronic.js)
* [LeapYear](Maths/LeapYear.js) * [LeapYear](Maths/LeapYear.js)
* [LinearSieve](Maths/LinearSieve.js) * [LinearSieve](Maths/LinearSieve.js)
* [LucasSeries](Maths/LucasSeries.js) * [LucasSeries](Maths/LucasSeries.js)
@ -197,6 +200,7 @@
* [SquareRoot](Maths/SquareRoot.js) * [SquareRoot](Maths/SquareRoot.js)
* [SumOfDigits](Maths/SumOfDigits.js) * [SumOfDigits](Maths/SumOfDigits.js)
* [SumOfGeometricProgression](Maths/SumOfGeometricProgression.js) * [SumOfGeometricProgression](Maths/SumOfGeometricProgression.js)
* [TwinPrime](Maths/TwinPrime.js)
* [Volume](Maths/Volume.js) * [Volume](Maths/Volume.js)
* [WhileLoopFactorial](Maths/WhileLoopFactorial.js) * [WhileLoopFactorial](Maths/WhileLoopFactorial.js)
* [ZellersCongruenceAlgorithm](Maths/ZellersCongruenceAlgorithm.js) * [ZellersCongruenceAlgorithm](Maths/ZellersCongruenceAlgorithm.js)

View File

@ -11,7 +11,7 @@
const secondLargestElement = (array) => { const secondLargestElement = (array) => {
const largestElement = Math.max(...array) const largestElement = Math.max(...array)
let element = 0 let element = -Number.MAX_VALUE
for (let i = 0; i < array.length; i++) { for (let i = 0; i < array.length; i++) {
if (element < array[i] && array[i] !== largestElement) { if (element < array[i] && array[i] !== largestElement) {