{"ScriptPreparationCode":"var arr = [7,1,5,3,6,4,5,6,7,8,9,12,43,7,0.5,3,56,78.5,6,3]\r\n\r\nconst isUndefined = (val) =\u003E typeof val === \u0027undefined\u0027\r\n\r\nfunction getProfit(prices = []) {\r\n let profit = 0\r\n\r\n for (let i=0; i\u003C prices.length; i\u002B\u002B) {\r\n for (let j=i \u002B 1; j \u003C prices.length; j\u002B\u002B) {\r\n if (!isUndefined(prices[j]) \u0026\u0026 prices[j] - prices[i] \u003E profit) {\r\n profit = prices[j] - prices[i]\r\n }\r\n }\r\n }\r\n\r\n return profit\r\n}\r\n\r\nfunction getProfit2(prices = []) {\r\n const min = Math.min(...prices)\r\n const minIndex = prices.indexOf(min)\r\n \r\n \r\n const max = Math.max(...prices.slice(minIndex))\r\n const maxIndex = prices.indexOf(max)\r\n \r\n if (maxIndex \u003E minIndex) {\r\n return max - min\r\n }\r\n \r\n return 0\r\n}\r\n","TestCases":[{"Name":"getProfit","Code":"getProfit(arr)","IsDeferred":false},{"Name":"getProfit2","Code":"getProfit2(arr)","IsDeferred":false}]}