Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calc_max_profit(ERT_YesterdayStockPrice) {
- var result = {
- "buyAt" : 0,
- "sellAt" : 0,
- "profit" : 0
- }
- right = 0;
- left = 0;
- for (var i = 0; i < ERT_YesterdayStockPrice.length; i++){
- if (ERT_YesterdayStockPrice[i] < ERT_YesterdayStockPrice[left]) {
- left = i;
- if (left > right) {
- right = left;
- }
- }
- if (ERT_YesterdayStockPrice[i] >= ERT_YesterdayStockPrice[right]) {
- right = i;
- }
- if (ERT_YesterdayStockPrice[right] - ERT_YesterdayStockPrice[left] > result.profit) {
- result.profit = ERT_YesterdayStockPrice[right] - ERT_YesterdayStockPrice[left];
- result.sellAt = right;
- result.buyAt = left;
- }
- }
- return result;
- }
Add Comment
Please, Sign In to add comment