fix(learn): rework Rosetta Code Count the Coins (#41282)
* fix: rework challenge to use argument in function * fix: use better wording Co-authored-by: Tom <20648924+moT01@users.noreply.github.com> Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
@ -30,7 +30,7 @@ There are four types of common coins in [US](https://en.wikipedia.org/wiki/Unite
|
|||||||
|
|
||||||
# --instructions--
|
# --instructions--
|
||||||
|
|
||||||
Implement a function to determine how many ways there are to make change for a dollar using these common coins (1 dollar = 100 cents)
|
Implement a function to determine how many ways there are to make change for a given input, `cents`, that represents an amount of US pennies using these common coins.
|
||||||
|
|
||||||
# --hints--
|
# --hints--
|
||||||
|
|
||||||
@ -40,10 +40,22 @@ Implement a function to determine how many ways there are to make change for a d
|
|||||||
assert(typeof countCoins === 'function');
|
assert(typeof countCoins === 'function');
|
||||||
```
|
```
|
||||||
|
|
||||||
`countCoins()` should return 242.
|
`countCoins(15)` should return `6`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
assert.equal(countCoins(), 242);
|
assert.equal(countCoins(15), 6);
|
||||||
|
```
|
||||||
|
|
||||||
|
`countCoins(85)` shouls return `163`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert.equal(countCoins(85), 163);
|
||||||
|
```
|
||||||
|
|
||||||
|
`countCoins(100)` should return `242`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
assert.equal(countCoins(100), 242);
|
||||||
```
|
```
|
||||||
|
|
||||||
# --seed--
|
# --seed--
|
||||||
@ -51,7 +63,7 @@ assert.equal(countCoins(), 242);
|
|||||||
## --seed-contents--
|
## --seed-contents--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function countCoins() {
|
function countCoins(cents) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -60,12 +72,11 @@ function countCoins() {
|
|||||||
# --solutions--
|
# --solutions--
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function countCoins() {
|
function countCoins(cents) {
|
||||||
let t = 100;
|
|
||||||
const operands = [1, 5, 10, 25];
|
const operands = [1, 5, 10, 25];
|
||||||
const targetsLength = t + 1;
|
const targetsLength = cents + 1;
|
||||||
const operandsLength = operands.length;
|
const operandsLength = operands.length;
|
||||||
t = [1];
|
const t = [1];
|
||||||
|
|
||||||
for (let a = 0; a < operandsLength; a++) {
|
for (let a = 0; a < operandsLength; a++) {
|
||||||
for (let b = 1; b < targetsLength; b++) {
|
for (let b = 1; b < targetsLength; b++) {
|
||||||
|
Reference in New Issue
Block a user