Last active
March 15, 2017 06:29
-
-
Save aditya2337/bfd8864bb98b624558e2885a64720517 to your computer and use it in GitHub Desktop.
Tip at Mars
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
function giveTip(currencyFirst, currencySecond, sum){ | |
let arr = []; | |
arr[0] = 0; | |
for(let i = 1; i <= sum; i++){ | |
let minA, minB; | |
if( i < currencyFirst){ | |
minA = currencyFirst - i; | |
}else{ | |
minA = arr[i - currencyFirst]; | |
} | |
if( i < currencySecond){ | |
minB = currencySecond - i; | |
} else { | |
minB = arr [i - currencySecond] | |
} | |
arr[i] = Math.min(minA, minB); | |
} | |
return arr[sum]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment