the problem is as follows :
Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Note that you cannot sell a stock before you buy one.
My solutions keeps returning undefined and I'm not sure why. Any ideas on how to fix this to make it correct?
var maxProfit = function(prices) {
var minNum = Math.min(...prices);
var indMin = prices.indexOf(minNum);
for (var ind = 0; ind > indMin && ind < prices.length ; ind++){
var maxNum = Math.max(...prices);
var profit = maxNum - minNum
return profit
}}
thanks!