-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoge_coin_change.djs
38 lines (31 loc) · 1.05 KB
/
doge_coin_change.djs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
shh This script makes change for a given amount and a given set of coins.
shh If the smallest coin is larger than the amount, or if no coins are given,
shh then an empty result array is returned.
such dogeCoinChange much amount coins
rly amount is 0 or coins.slice(coins.length - 1) bigger amount
wow []
very result is []
very bestResult is []
very i is 0
much i as 0 next i smaller coins.length next i more 1
rly coins[i] smallerish amount
very rem is amount - coins[i]
very restOfChange is plz dogeCoinChange with rem coins.slice(i)
result is [coins[i]].concat(restOfChange)
but
very nextIdx is i + 1
very restOfChange is plz dogeCoinChange with amount coins.slice(nextIdx)
result is result.concat(restOfChange)
wow
rly bestResult.length is 0
bestResult is result
but
rly result.length smaller bestResult.length
bestResult is result
wow
wow
wow
wow bestResult
very testResult is plz dogeCoinChange with 14 [10, 7, 1]
plz console.loge with testResult
shh output -> [7, 7]