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

Initial commit.

parents
Branches main
No related tags found
No related merge requests found
export class Accumulator {
constructor() {
this.content = [];
}
addAll(content) {
// INSTRUCTIONS: Change the arguments to the `push` method so that all of
// the elements in `content` are added as elements to `this.content`.
//
// Resources:
// <https://javascript.info/array#methods-pop-push-shift-unshift>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push>
// <https://javascript.info/rest-parameters-spread#spread-syntax>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax>
this.content.push();
}
}
export class Accumulator {
constructor() {
this.content = [];
}
addAll(content) {
this.content.push(...content);
}
}
import { Accumulator } from './spreadOperator.js';
describe('the `Accumulator` class', () => {
test('starts out empty', () => {
const accumulator = new Accumulator();
expect(accumulator.content).toEqual([]);
});
test('can accumulate one element at a time', () => {
const accumulator = new Accumulator();
accumulator.addAll(['foo']);
accumulator.addAll(['bar']);
expect(accumulator.content).toEqual(['foo', 'bar']);
});
test('can accumulate several elements at once', () => {
const accumulator = new Accumulator();
accumulator.addAll(['foo', 'bar', 'baz']);
expect(accumulator.content).toEqual(['foo', 'bar', 'baz']);
});
});
export function makeBetweenFilter(low, high) {
// INSTRUCTIONS: Return an arrow function that checks whether a number is
// between low (inclusive) and high (exclusive).
//
// Resources:
// <https://javascript.info/arrow-functions-basics>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures>
// <https://javascript.info/closure#lexical-environment>
}
export function makeBetweenFilter(low, high) {
return (number) => low <= number && number < high;
}
import { makeBetweenFilter } from './arrowFunctions.js';
describe('the `makeBetweenFilter` function', () => {
test('makes a filter that rejects numbers that are below the lower bound', () => {
const filter = makeBetweenFilter(0, 10);
expect(filter(-1)).toBe(false);
});
test('makes a filter that accepts numbers that are the lower bound', () => {
const filter = makeBetweenFilter(0, 10);
expect(filter(0)).toBe(true);
});
test('makes a filter that accepts numbers that are between the bounds', () => {
const filter = makeBetweenFilter(0, 10);
expect(filter(1)).toBe(true);
expect(filter(9)).toBe(true);
});
test('makes a filter that rejects numbers that are the upper bound', () => {
const filter = makeBetweenFilter(0, 10);
expect(filter(10)).toBe(false);
});
test('makes a filter that rejects numbers that are above the upper bound', () => {
const filter = makeBetweenFilter(0, 10);
expect(filter(11)).toBe(false);
});
});
This diff is collapsed.
{
"name": "@unlsoft/javascript-practice",
"version": "1.0.0",
"description": "A collection of small JavaScript exercises for practice when learning the language.",
"private": true,
"license": "UNLICENSED",
"scripts": {
"postinstall:eslint-config": "cd eslint-config && npm install",
"postinstall:app": "cd javascript-practice && npm install",
"postinstall": "run-s postinstall:**",
"lint:app": "cd javascript-practice && npm run lint",
"lint": "run-s --continue-on-error lint:**",
"test-once:a": "cd javascript-practice && npm run test-once:a",
"test-once:b": "cd javascript-practice && npm run test-once:b",
"test-once:c": "cd javascript-practice && npm run test-once:c",
"test-once:d": "cd javascript-practice && npm run test-once:d",
"test-once:e": "cd javascript-practice && npm run test-once:e",
"test-once:f": "cd javascript-practice && npm run test-once:f",
"test-once:g": "cd javascript-practice && npm run test-once:g",
"test-once:h": "cd javascript-practice && npm run test-once:h",
"test-once:i": "cd javascript-practice && npm run test-once:i",
"test-once:j": "cd javascript-practice && npm run test-once:j",
"test-once:k": "cd javascript-practice && npm run test-once:k",
"test-once:l": "cd javascript-practice && npm run test-once:l",
"test-once:m": "cd javascript-practice && npm run test-once:m",
"test-once:n": "cd javascript-practice && npm run test-once:n",
"test-once:o": "cd javascript-practice && npm run test-once:o",
"test-once:p": "cd javascript-practice && npm run test-once:p",
"test-once:q": "cd javascript-practice && npm run test-once:q",
"test-once:r": "cd javascript-practice && npm run test-once:r",
"test-once:s": "cd javascript-practice && npm run test-once:s",
"test-once": "cd javascript-practice && npm run test-once",
"test": "run-s test-once"
},
"devDependencies": {
"ghooks": "^2.0.4",
"npm-run-all": "^4.1.5"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment