Created
November 21, 2018 20:42
-
-
Save tamunoibi/c683ccac81ce429bcab2fa6dba8a4238 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 countChange (money,coins) { | |
| const arr = []; | |
| let sum; | |
| for(let i = 0; i < coins.length; i++) { | |
| for(let j = 0; j < coins.length; j++) { | |
| let value = coins[i] + coins[j]; | |
| //console.log(value, value, value); | |
| if(value === money) { | |
| arr.push(value); | |
| } | |
| //console.log(coins[i], coins[j]); | |
| } | |
| } | |
| coins.forEach(e => { | |
| sum = e; | |
| while (sum < money) { | |
| sum += e; | |
| if(sum === money) { | |
| arr.push(sum); | |
| } | |
| } | |
| }); | |
| let bigHead = coins.reduce(function (accumulator, currentValue) { | |
| return accumulator + currentValue; | |
| }, 0); | |
| if (bigHead === money) { | |
| arr.push(bigHead); | |
| } | |
| return arr.length; | |
| } | |
| countChange(10, [5, 2, 3]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment