You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this uses a nested ‘for’ loop to compare two elements in an array and return the two with the largest change, in which the smallest number exists in the array before the larger number.
returning an array with the index of the day to ‘buy’ in index[0] and the day to ‘sell’ in index[1]
function get_rich_buying_apple_stock(array) {
var times_to_buy_sell = [];
var best = 0;
for (var i = 0; i < stock_prices_yesterday.length; i++) {
for (var j = i+1; j < stock_prices_yesterday.length; j++) {
if (stock_prices_yesterday[i] < stock_prices_yesterday[j]) {
current = stock_prices_yesterday[i] - stock_prices_yesterday[j];