Skip to content

Instantly share code, notes, and snippets.

View nickGermi's full-sized avatar

nickGermi

  • Sydney, Australia
View GitHub Profile
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];