Created
May 10, 2024 10:20
-
-
Save vnegi10/18b54b41dd0e2fc4524370d447ee622c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getTopPerformer(breakdown, num_days) { | |
const changeArray = [] | |
for (let i = 0; i < names.length; i++) { | |
const changeObj = { | |
name: names[i], | |
change: (breakdown[breakdown.length - 1][names[i]] - | |
breakdown[breakdown.length - 1 - num_days][names[i]]) | |
/ breakdown[breakdown.length - 1- num_days][names[i]] | |
} | |
changeArray.push(changeObj) | |
} | |
// Find maximum value and its corresponding index in changeArray | |
let maxValue = -Infinity; | |
let maxIndex = -1; | |
for (let i = 0; i < changeArray.length; i++) { | |
if (changeArray[i].change > maxValue) { | |
maxValue = changeArray[i].change; | |
maxIndex = i; | |
} | |
} | |
// Change % | |
const maxChange = maxValue * 100; | |
// Round off to first digit after decimal | |
const roundMaxChange = Math.round(maxChange * 10) / 10; | |
const resultObj = { | |
maxChange: roundMaxChange, | |
maxName: tickers[maxIndex] | |
} | |
return resultObj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment