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

Updated dependencies and expanded documentation.

parent de9cbee2
No related branches found
No related tags found
No related merge requests found
Showing
with 3247 additions and 3751 deletions
Subproject commit 24df42fb655d234b83c93b0fb24d012e4d9ecb58 Subproject commit 16524f5ac58d4b13378261f1ab29bc1acc2a2099
This diff is collapsed.
{ {
"name": "@unlsoft/javascript-practice", "name": "@unlcsce/javascript-practice",
"version": "1.0.0", "version": "1.0.0",
"description": "A collection of small JavaScript exercises for practice when learning the language.", "description": "A collection of small JavaScript exercises for practice when learning the language.",
"type": "module", "type": "module",
...@@ -8,25 +8,25 @@ ...@@ -8,25 +8,25 @@
"scripts": { "scripts": {
"lint:js": "eslint --max-warnings 0 ./src", "lint:js": "eslint --max-warnings 0 ./src",
"lint": "run-s --continue-on-error lint:**", "lint": "run-s --continue-on-error lint:**",
"test-once:a": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'formatAsTriple function'", "test-once:a": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`formatAsTriple` function'",
"test-once:b": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'first classify function'", "test-once:b": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`classify` function'",
"test-once:c": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'second classify function'", "test-once:c": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`decodeCountingNumber` function'",
"test-once:d": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'countDigits function'", "test-once:d": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`countDigits` function'",
"test-once:e": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'triangularNumber function'", "test-once:e": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`triangularNumber` function'",
"test-once:f": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'sum function'", "test-once:f": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`sum` function'",
"test-once:g": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'first Book class'", "test-once:g": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'first `Book` class'",
"test-once:h": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'second Book class'", "test-once:h": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'second `Book` class'",
"test-once:i": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'Temperature class'", "test-once:i": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`Temperature` class'",
"test-once:j": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'first PlanarVector class'", "test-once:j": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'first `PlanarVector` class'",
"test-once:k": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'second PlanarVector class'", "test-once:k": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'second `PlanarVector` class'",
"test-once:l": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'Swappable class'", "test-once:l": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`Swappable` class'",
"test-once:m": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'countDistinctElements function'", "test-once:m": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`countDistinctElements` function'",
"test-once:n": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'findMostCommonCharacter function'", "test-once:n": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`findMostCommonCharacter` function'",
"test-once:o": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'summarize function'", "test-once:o": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`summarize` function'",
"test-once:p": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'formatArithmeticProgression function'", "test-once:p": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`formatArithmeticProgression` function'",
"test-once:q": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'countArguments function'", "test-once:q": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`countArguments` function'",
"test-once:r": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'Accumulator class'", "test-once:r": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`Accumulator` class'",
"test-once:s": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t 'makeBetweenFilter function'", "test-once:s": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t '`makeBetweenFilter` function'",
"test-once": "node --experimental-vm-modules node_modules/jest/bin/jest.js", "test-once": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watchAll" "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watchAll"
}, },
...@@ -34,18 +34,19 @@ ...@@ -34,18 +34,19 @@
"npm-run-all": "^4.1.5" "npm-run-all": "^4.1.5"
}, },
"devDependencies": { "devDependencies": {
"@unlsoft/eslint-config": "file:../eslint-config", "@unlcsce/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": "@unlcsce"
}, },
"jest": { "jest": {
"clearMocks": true, "clearMocks": true,
"collectCoverageFrom": [ "collectCoverageFrom": [
"src/**/*.js" "src/**/*.js",
"!src/testing/**/*.js"
], ],
"resetMocks": false, "resetMocks": false,
"restoreMocks": false, "restoreMocks": false,
......
...@@ -2,4 +2,9 @@ export function formatAsTriple(x, y, z) { ...@@ -2,4 +2,9 @@ export function formatAsTriple(x, y, z) {
// INSTRUCTIONS: Given three coordinates, return a template literal that // INSTRUCTIONS: Given three coordinates, return a template literal that
// formats them as a three-coordinate triple. For example, formatAsTriple(4, // formats them as a three-coordinate triple. For example, formatAsTriple(4,
// 5, 6) should return the string '(4, 5, 6)'. // 5, 6) should return the string '(4, 5, 6)'.
//
// Resources:
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals>
// <https://javascript.info/types#string>
// <https://javascript.info/string#quotes>
} }
/* eslint-disable no-magic-numbers */
import { formatAsTriple } from './templateLiterals.js'; import { formatAsTriple } from './templateLiterals.js';
describe('the formatAsTriple function', () => { describe('the `formatAsTriple` function', () => {
test('correctly formats the triple (0, 0, 0)', () => { test('correctly formats the triple (0, 0, 0)', () => {
expect(formatAsTriple(0, 0, 0)).toBe('(0, 0, 0)'); expect(formatAsTriple(0, 0, 0)).toBe('(0, 0, 0)');
}); });
......
export function classify(number) { export function classify(number) {
let description = 'not a'; let description = 'not a';
// INSTRUCTIONS: Use a chained conditional to set the variable description to // INSTRUCTIONS: Use a chained conditional to set the variable `description`
// 'negative' when number is negative, 'zero' when number is zero, and // to 'negative' when number is negative, 'zero' when number is zero, and
// 'positive' when number is positive. If number is none of those (for // 'positive' when number is positive. If number is none of those (for
// example, if number is NaN), leave the description as it is. // example, if number is NaN), leave the description as it is.
//
// Resources:
// <https://javascript.info/ifelse#several-conditions-else-if>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else>
return `${description} number`; return `${description} number`;
} }
/* eslint-disable no-magic-numbers */
import { classify } from './conditionals.js'; import { classify } from './conditionals.js';
describe('the first classify function', () => { describe('the `classify` function', () => {
test('correctly classifies a negative infinite number', () => { test('correctly classifies a negative infinite number', () => {
expect(classify(-Infinity)).toBe('negative number'); expect(classify(-Infinity)).toBe('negative number');
}); });
......
...@@ -5,5 +5,9 @@ export function decodeCountingNumber(word) { ...@@ -5,5 +5,9 @@ export function decodeCountingNumber(word) {
// INSTRUCTIONS: Use a switch statement to set meaning to 0, 1, 2, 3, or 4 if // INSTRUCTIONS: Use a switch statement to set meaning to 0, 1, 2, 3, or 4 if
// word is 'zero', 'one', two', 'three', or 'four', respectively. Leave // word is 'zero', 'one', two', 'three', or 'four', respectively. Leave
// meaning undefined in the default case. // meaning undefined in the default case.
//
// Resources:
// <https://javascript.info/switch>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch>
return `The word "${word}" is associated with the meaning ${meaning}.`; return `The word "${word}" is associated with the meaning ${meaning}.`;
} }
import { decodeCountingNumber } from './switchStatements.js'; import { decodeCountingNumber } from './switchStatements.js';
describe('the second classify function', () => { describe('the `decodeCountingNumber` function', () => {
test('correctly interprets the word "zero"', () => { test('correctly interprets the word "zero"', () => {
expect(decodeCountingNumber('zero')).toBe('The word "zero" is associated with the meaning 0.'); expect(decodeCountingNumber('zero')).toBe('The word "zero" is associated with the meaning `0`.');
}); });
test('correctly interprets the word "one"', () => { test('correctly interprets the word "one"', () => {
expect(decodeCountingNumber('one')).toBe('The word "one" is associated with the meaning 1.'); expect(decodeCountingNumber('one')).toBe('The word "one" is associated with the meaning `1`.');
}); });
test('correctly interprets the word "two"', () => { test('correctly interprets the word "two"', () => {
expect(decodeCountingNumber('two')).toBe('The word "two" is associated with the meaning 2.'); expect(decodeCountingNumber('two')).toBe('The word "two" is associated with the meaning `2`.');
}); });
test('correctly interprets the word "three"', () => { test('correctly interprets the word "three"', () => {
expect(decodeCountingNumber('three')).toBe('The word "three" is associated with the meaning 3.'); expect(decodeCountingNumber('three')).toBe('The word "three" is associated with the meaning `3`.');
}); });
test('correctly interprets the word "four"', () => { test('correctly interprets the word "four"', () => {
expect(decodeCountingNumber('four')).toBe('The word "four" is associated with the meaning 4.'); expect(decodeCountingNumber('four')).toBe('The word "four" is associated with the meaning `4`.');
}); });
test('correctly interprets the word "five"', () => { test('correctly interprets the word "five"', () => {
expect(decodeCountingNumber('five')).toBe('The word "five" is associated with the meaning undefined.'); expect(decodeCountingNumber('five')).toBe('The word "five" is associated with the meaning `undefined`.');
}); });
}); });
export function countDigits(positiveInteger) { export function countDigits(positiveInteger) {
let result = 0; let result = 0;
let remainingDigits = positiveInteger; let remainingDigits = positiveInteger;
// INSTRUCTIONS: Write a loop here that it runs as long as remainingDigits is // INSTRUCTIONS: Write a loop here that runs as long as `remainingDigits` is
// still positive, and on each iteration increments result and updates // still positive, and on each iteration increments result and updates
// remainingDigits to Math.floor(remainingDigits / 10). // `remainingDigits` to `Math.floor(remainingDigits / 10)`.
//
// Resources:
// <https://javascript.info/while-for#the-while-loop>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while>
// <https://javascript.info/operators#increment-decrement>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Increment>
// <https://javascript.info/number#rounding>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor>
return result; return result;
} }
/* eslint-disable no-magic-numbers */
import { countDigits } from './whileLoops.js'; import { countDigits } from './whileLoops.js';
describe('the countDigits function', () => { describe('the `countDigits` function', () => {
test('counts digits in a one-digit positive integer', () => { test('counts digits in a one-digit positive integer', () => {
expect(countDigits(5)).toBe(1); expect(countDigits(5)).toBe(1);
}); });
......
...@@ -2,7 +2,13 @@ export function triangularNumber(termCount) { ...@@ -2,7 +2,13 @@ export function triangularNumber(termCount) {
let result = 0; let result = 0;
// INSTRUCTIONS: Write a counter-based loop here so that the loop variable // INSTRUCTIONS: Write a counter-based loop here so that the loop variable
// begins at zero, the loop variable goes up by one each iteration, and the // begins at zero, the loop variable goes up by one each iteration, and the
// loop terminates as soon as the loop variable reaches termCount. Inside the // loop terminates as soon as the loop variable reaches `termCount`. Inside
// loop, add the loop variable to result. // the loop, add the loop variable to `result`.
//
// Resources:
// <https://javascript.info/while-for#the-for-loop>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for>
// <https://javascript.info/operators#modify-in-place>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment>
return result; return result;
} }
/* eslint-disable no-magic-numbers */
import { triangularNumber } from './counterBasedForLoops.js'; import { triangularNumber } from './counterBasedForLoops.js';
describe('the triangularNumber function', () => { describe('the `triangularNumber` function', () => {
test('computes the zeroth triangular number', () => { test('computes the zeroth triangular number', () => {
expect(triangularNumber(0)).toBe(0); expect(triangularNumber(0)).toBe(0);
}); });
......
...@@ -2,5 +2,11 @@ export function sum(collection) { ...@@ -2,5 +2,11 @@ export function sum(collection) {
let result = 0; let result = 0;
// INSTRUCTIONS: Write a loop that iterates over the given collection of // INSTRUCTIONS: Write a loop that iterates over the given collection of
// numbers and adds each element to the result. // numbers and adds each element to the result.
//
// Resources:
// <https://javascript.info/array#loops>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of>
// <https://javascript.info/operators#modify-in-place>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment>
return result; return result;
} }
/* eslint-disable no-magic-numbers */
import { sum } from './forEachLoops.js'; import { sum } from './forEachLoops.js';
describe('the sum function', () => { describe('the `sum` function', () => {
test('totals elements of an empty', () => { test('totals elements of an empty', () => {
expect(sum([])).toBe(0); expect(sum([])).toBe(0);
}); });
......
export class Book { export class Book {
// INSTRUCTIONS: Write a constructor that takes two parameters, title and // INSTRUCTIONS: Write a constructor that takes two parameters, `title` and
// author, and stores them in two public fields, this.title and this.author. // `author`, and stores them in two public fields, `this.title` and
// `this.author`.
//
// Resources:
// <https://javascript.info/class>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor>
} }
import { Book } from './constructorsAndFields.js'; import { Book } from './constructorsAndFields.js';
describe('the first Book class', () => { describe('the first `Book` class', () => {
test('has title and author fields and no others', () => { test('has `title` and `author` fields and no others', () => {
const book = new Book('A Title', 'An Author'); const book = new Book('A Title', 'An Author');
expect(Object.getOwnPropertyNames(book).sort()).toEqual(['author', 'title']); expect(Object.getOwnPropertyNames(book).sort()).toEqual(['author', 'title']);
}); });
......
export class Book { export class Book {
// INSTRUCTIONS: Write a constructor that takes two parameters, title and // INSTRUCTIONS: Write a constructor that takes two parameters, `title` and
// author, and stores them in two protected fields, this._title and // `author`, and stores them in two protected fields, `this._title` and
// this._author. // `this._author`.
//
// Resources:
// <https://javascript.info/class>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor>
// INSTRUCTIONS: Write a getter so that if b is a book with title X and author // INSTRUCTIONS: Write a getter so that if `b` is a book with title 'X' and
// Y, b.entry is equal to the string 'X by Y'. // author 'Y', then `b.entry` is equal to the string 'X by Y'.
//
// Resources:
// <https://javascript.info/private-protected-properties-methods>
// <https://javascript.info/class#getters-setters>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals>
// <https://javascript.info/types#string>
// <https://javascript.info/string#quotes>
} }
/* eslint-disable no-underscore-dangle */
import { Book } from './protectedFieldsAndGetters.js'; import { Book } from './protectedFieldsAndGetters.js';
describe('the second Book class', () => { describe('the second `Book` class', () => {
test('has _title and _author fields and no others', () => { test('has `_title` and `_author` fields and no others', () => {
const book = new Book('A Title', 'An Author'); const book = new Book('A Title', 'An Author');
expect(Object.getOwnPropertyNames(book).sort()).toEqual(['_author', '_title']); expect(Object.getOwnPropertyNames(book).sort()).toEqual(['_author', '_title']);
}); });
......
...@@ -10,7 +10,11 @@ export class Temperature { ...@@ -10,7 +10,11 @@ export class Temperature {
return FAHRENHEIT_FREEZING + FAHRENHEIT_PER_CELSIUS * this.celsius; return FAHRENHEIT_FREEZING + FAHRENHEIT_PER_CELSIUS * this.celsius;
} }
// INSTRUCTIONS: Write a setter so that if t is a temperature, a statement // INSTRUCTIONS: Write a setter so that if `t` is a `Temperature` object, a
// like t.fahrenheit = 32; will set t.celsius to the equivalent temperature in // statement like `t.fahrenheit = 32;` will set `t.celsius` to the equivalent
// Celsius. // temperature in Celsius.
//
// Resources:
// <https://javascript.info/class#getters-setters>
// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set>
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment