const maxProfit = prices => { let arr = []; for (let i = 0; i < prices.length; i++) { for (let j = i+1; j < prices.length; j++) { arr.push(prices[j] - prices[i]); } } const Max = Math.max(...arr) if (Max > 0) { return Max } else { return 0 } };