This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stockPrices = [10, 7, 5, 8, 11, 9]; | |
/* | |
Takes an array of stock prices and returns the best profit could have been made from 1 purchase and 1 sale of 1 stock | |
*/ | |
function getProfit(inputArray){ | |
//find minimum of first 2 items of the array | |
var min = inputArray[0] < inputArray[1] ? inputArray[0] : inputArray[1]; | |
//find difference of second item minus first | |
var diff = inputArray[1] - inputArray[0]; |