Skip to content
Snippets Groups Projects
Commit 741e199c authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Updated dependencies.

parent 173a4482
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
}, },
"devDependencies": { "devDependencies": {
"@unlsoft/eslint-config": "file:../eslint-config", "@unlsoft/eslint-config": "file:../eslint-config",
"eslint": "^7.30.0", "eslint": "^8.20.0",
"jest": "^27.0.6", "jest": "^28.1.3",
"jest-environment-node": "^27.0.6" "jest-environment-node": "^28.1.3"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "@unlsoft" "extends": "@unlsoft"
......
class Backpointer { class Backpointer {
constructor() { constructor(coin, count) {
// TODO: stub this.coin = coin;
this.count = count;
} }
} }
const IMPOSSIBLE = new Backpointer(/* TODO: arguments needed */); const IMPOSSIBLE = new Backpointer(undefined, Infinity);
function chooseBackpointer(coins, backpointers) { function chooseBackpointer(coins, backpointers) {
const currentAmount = backpointers.length; const currentAmount = backpointers.length;
let best = IMPOSSIBLE; let best = IMPOSSIBLE;
// TODO: stub for (const coin of coins) {
const previousAmount = currentAmount - coin;
if (previousAmount >= 0) {
const candidate = new Backpointer(
coin,
backpointers[previousAmount].count + 1,
);
if (candidate.count < best.count) {
best = candidate;
}
}
}
console.assert( console.assert(
best !== IMPOSSIBLE, best !== IMPOSSIBLE,
`Found no coin small enough for making change for ${currentAmount}, ` + `Found no coin small enough for making change for ${currentAmount}, ` +
...@@ -24,11 +36,13 @@ export function makeChange(coins, amount) { ...@@ -24,11 +36,13 @@ export function makeChange(coins, amount) {
console.assert(coins.includes(1), 'Tried to make change without a 1¢ coin available.'); console.assert(coins.includes(1), 'Tried to make change without a 1¢ coin available.');
console.assert(Number.isInteger(amount), `Tried to make change for the nonintegral amount ${amount}¢.`); console.assert(Number.isInteger(amount), `Tried to make change for the nonintegral amount ${amount}¢.`);
console.assert(amount >= 0, `Tried to make change for the negative amount ${amount}¢.`); console.assert(amount >= 0, `Tried to make change for the negative amount ${amount}¢.`);
const backpointers = [/* TODO: initial backpointers */]; const backpointers = [new Backpointer(undefined, 0)];
while (false /* TODO: condition */) { while (backpointers.length <= amount) {
backpointers.push(chooseBackpointer(coins, backpointers)); backpointers.push(chooseBackpointer(coins, backpointers));
} }
const results = []; const results = [];
// TODO: stub for (let remainingAmount = amount; remainingAmount > 0; remainingAmount -= backpointers[remainingAmount].coin) {
results.push(backpointers[remainingAmount].coin);
}
return results.reverse(); return results.reverse();
} }
/* eslint-disable no-magic-numbers */
import { makeChange } from './makeChange.js'; import { makeChange } from './makeChange.js';
describe('makeChange makes change using the fewest possible number of coins', () => { describe('makeChange makes change using the fewest possible number of coins', () => {
......
import NodeEnvironment from 'jest-environment-node'; import jestEnvironmentNode from 'jest-environment-node';
export default class FailFastEnvironment extends NodeEnvironment { export default class FailFastEnvironment extends jestEnvironmentNode.default {
constructor(...rest) { constructor(...rest) {
super(...rest); super(...rest);
this.failed = false; this.failed = false;
......
Subproject commit 24df42fb655d234b83c93b0fb24d012e4d9ecb58 Subproject commit a85278e2bd62f637800bc32fa6b372bc2855546e
This diff is collapsed.
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
"lint": "run-s --continue-on-error lint:**", "lint": "run-s --continue-on-error lint:**",
"test-once:app": "cd dynamic-programming && npm run test-once", "test-once:app": "cd dynamic-programming && npm run test-once",
"test-once": "run-s --continue-on-error test-once:**", "test-once": "run-s --continue-on-error test-once:**",
"test": "run-s test-once", "test": "run-s test-once"
"start": "cd dynamic-programming && npm run start",
"build:app": "cd dynamic-programming && npm run build",
"build": "run-s build:**"
}, },
"devDependencies": { "devDependencies": {
"ghooks": "^2.0.4", "ghooks": "^2.0.4",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment