From 026cdd520d548a217a99aee9ffdee78f7c81d5b7 Mon Sep 17 00:00:00 2001 From: Jerome Covington Date: Wed, 7 Feb 2024 16:09:53 -0500 Subject: [PATCH 1/5] update bst node --- lists-and-trees/bst-node.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lists-and-trees/bst-node.js b/lists-and-trees/bst-node.js index 6de6aeb..ed9f551 100644 --- a/lists-and-trees/bst-node.js +++ b/lists-and-trees/bst-node.js @@ -1,27 +1,31 @@ export default class Node { constructor(data) { - this.data = data; - this.left = null; - this.right = null; + this.data = data + this.left = null + this.right = null + } + + setData(d) { + this.data = d } getData() { - return this.data; + return this.data } setLeft(n) { - this.left = n || null; + this.left = n || null } setRight(n) { - this.right = n || null; + this.right = n || null } getLeft() { - return this.left; + return this.left } getRight() { - return this.right; + return this.right } } From a79f9f6edad982e40bd472eddb0a12b75341e1ae Mon Sep 17 00:00:00 2001 From: Jerome Covington Date: Wed, 7 Feb 2024 16:10:04 -0500 Subject: [PATCH 2/5] update packages with prettier --- .eslintrc.json | 6 --- package-lock.json | 119 +++++++++++++++++++--------------------------- package.json | 9 ++-- 3 files changed, 56 insertions(+), 78 deletions(-) delete mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index df0ef6a..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "airbnb-base", - "plugins": [ - "import" - ] -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 536e22a..a6b857f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,9 +11,11 @@ "devDependencies": { "chai": "^5.0.3", "eslint": "^8.56.0", - "eslint-config-airbnb-base": "^15.0.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", - "mocha": "^10.2.0" + "mocha": "^10.2.0", + "prettier": "^3.2.5", + "prettier-config-standard": "^7.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -599,12 +601,6 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, - "node_modules/confusing-browser-globals": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz", - "integrity": "sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==", - "dev": true - }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -705,15 +701,15 @@ } }, "node_modules/doctrine": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", - "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", "dev": true, "dependencies": { "esutils": "^2.0.2" }, "engines": { - "node": ">=0.10.0" + "node": ">=6.0.0" } }, "node_modules/emoji-regex": { @@ -906,23 +902,16 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint-config-airbnb-base": { - "version": "15.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-15.0.0.tgz", - "integrity": "sha512-xaX3z4ZZIcFLvh2oUNvcX5oEofXda7giYmuplVxoOg5A7EXJMrUyqRgR+mhDhPK8LZ4PttFOBvCYDbX3sUoUig==", + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", "dev": true, - "dependencies": { - "confusing-browser-globals": "^1.0.10", - "object.assign": "^4.1.2", - "object.entries": "^1.1.5", - "semver": "^6.3.0" - }, - "engines": { - "node": "^10.12.0 || >=12.0.0" + "bin": { + "eslint-config-prettier": "bin/cli.js" }, "peerDependencies": { - "eslint": "^7.32.0 || ^8.2.0", - "eslint-plugin-import": "^2.25.2" + "eslint": ">=7.0.0" } }, "node_modules/eslint-import-resolver-node": { @@ -945,12 +934,6 @@ "ms": "^2.1.1" } }, - "node_modules/eslint-import-resolver-node/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true - }, "node_modules/eslint-module-utils": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz", @@ -977,12 +960,6 @@ "ms": "^2.1.1" } }, - "node_modules/eslint-module-utils/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true - }, "node_modules/eslint-plugin-import": { "version": "2.29.1", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.29.1.tgz", @@ -1023,11 +1000,17 @@ "ms": "^2.1.1" } }, - "node_modules/eslint-plugin-import/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true + "node_modules/eslint-plugin-import/node_modules/doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=0.10.0" + } }, "node_modules/eslint-scope": { "version": "7.2.2", @@ -1057,18 +1040,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "dev": true, - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/espree": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", @@ -2146,20 +2117,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/object.entries": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.7.tgz", - "integrity": "sha512-jCBs/0plmPsOnrKAfFQXRG2NFjlhZgjjcBLSmTnEhU8U6vVTsVe8ANeQJCHTl3gSsI4J+0emOoCgoKlmQPMgmA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.2.0", - "es-abstract": "^1.22.1" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/object.fromentries": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/object.fromentries/-/object.fromentries-2.0.7.tgz", @@ -2338,6 +2295,30 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-config-standard": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/prettier-config-standard/-/prettier-config-standard-7.0.0.tgz", + "integrity": "sha512-NgZy4TYupJR6aMMuV/Aqs0ONnVhlFT8PXVkYRskxREq8EUhJHOddVfBxPV6fWpgcASpJSgvvhVLk0CBO5M3Hvw==", + "dev": true, + "peerDependencies": { + "prettier": "^2.6.0 || ^3.0.0" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/package.json b/package.json index 0666930..e80b1a3 100644 --- a/package.json +++ b/package.json @@ -4,15 +4,18 @@ "description": "Some basic algorithms", "main": "index.js", "engine": "node >= 18", - "dependencies": {}, "devDependencies": { "chai": "^5.0.3", "eslint": "^8.56.0", - "eslint-config-airbnb-base": "^15.0.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", - "mocha": "^10.2.0" + "mocha": "^10.2.0", + "prettier": "^3.2.5", + "prettier-config-standard": "^7.0.0" }, "scripts": { + "lint": "eslint **/*.js", + "fixup": "eslint --fix **/*.js", "test": "mocha **/*.spec.js" }, "author": "Jerome Covington", From f38e7007185be59c5d79fa9ada3d147a41e898a9 Mon Sep 17 00:00:00 2001 From: Jerome Covington Date: Wed, 7 Feb 2024 16:19:29 -0500 Subject: [PATCH 3/5] add configs --- .eslintrc.json | 8 ++++++++ .prettierrc.json | 1 + package.json | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .prettierrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..d187a8c --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "extends": [ + "prettier" + ], + "parserOptions": { + "sourceType": "module" + } +} diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1 @@ +{} diff --git a/package.json b/package.json index e80b1a3..1c3ef1c 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "prettier-config-standard": "^7.0.0" }, "scripts": { - "lint": "eslint **/*.js", - "fixup": "eslint --fix **/*.js", + "prettier": "prettier \"**/*.{js,md}\" --check", + "prettier:fix": "prettier \"**/*.{js,md}\" --write", "test": "mocha **/*.spec.js" }, "author": "Jerome Covington", From 416b983513a95a7b85d183d38084aba89e896aa3 Mon Sep 17 00:00:00 2001 From: Jerome Covington Date: Wed, 7 Feb 2024 16:22:59 -0500 Subject: [PATCH 4/5] prettier fix --- README.md | 1 + lists-and-trees/bst-node.js | 18 ++--- lists-and-trees/linked-list-node.js | 2 +- lists-and-trees/linked-list.js | 6 +- lists-and-trees/test/linked-list-node.spec.js | 26 +++---- lists-and-trees/test/linked-list.spec.js | 68 ++++++++++--------- misc/binary-search.js | 2 +- misc/luhn.js | 13 ++-- misc/primes.js | 5 +- misc/test/binary-search.spec.js | 14 ++-- misc/test/luhn.spec.js | 12 ++-- misc/test/primes.spec.js | 10 +-- sorting/binaryToDecimal.js | 6 +- sorting/bubbleSort.js | 6 +- sorting/compare.js | 3 +- sorting/insertionSort.js | 6 +- sorting/ponySort.js | 6 +- sorting/sortByLessThanTally.js | 2 +- sorting/swap.js | 2 +- sorting/tally.js | 4 +- sorting/test/binaryToDecimal.spec.js | 9 ++- sorting/test/bubbleSort.spec.js | 12 ++-- sorting/test/compare.spec.js | 13 ++-- sorting/test/insertionSort.spec.js | 12 ++-- sorting/test/ponySort.spec.js | 8 +-- sorting/test/sortByLessThanTally.spec.js | 32 ++++++--- sorting/test/swap.spec.js | 8 +-- sorting/test/tally.spec.js | 28 ++++++-- sorting/test/tallyAndSort.spec.js | 14 ++-- sorting/test/visit.spec.js | 10 +-- sorting/test/visitAndCompare.spec.js | 10 +-- sorting/visit.js | 2 +- 32 files changed, 202 insertions(+), 168 deletions(-) diff --git a/README.md b/README.md index 43b7832..5cc12da 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # practical-algorithms + Old Possum's Repo of Practical Algorithms & Data Structures diff --git a/lists-and-trees/bst-node.js b/lists-and-trees/bst-node.js index ed9f551..a1f0c95 100644 --- a/lists-and-trees/bst-node.js +++ b/lists-and-trees/bst-node.js @@ -1,31 +1,31 @@ export default class Node { constructor(data) { - this.data = data - this.left = null - this.right = null + this.data = data; + this.left = null; + this.right = null; } setData(d) { - this.data = d + this.data = d; } getData() { - return this.data + return this.data; } setLeft(n) { - this.left = n || null + this.left = n || null; } setRight(n) { - this.right = n || null + this.right = n || null; } getLeft() { - return this.left + return this.left; } getRight() { - return this.right + return this.right; } } diff --git a/lists-and-trees/linked-list-node.js b/lists-and-trees/linked-list-node.js index 3f61183..47da9f1 100644 --- a/lists-and-trees/linked-list-node.js +++ b/lists-and-trees/linked-list-node.js @@ -15,4 +15,4 @@ export default class Node { getNext() { return this.next; } -}; +} diff --git a/lists-and-trees/linked-list.js b/lists-and-trees/linked-list.js index de6b1a8..a67e6e6 100644 --- a/lists-and-trees/linked-list.js +++ b/lists-and-trees/linked-list.js @@ -1,4 +1,4 @@ -import Node from './linked-list-node'; +import Node from "./linked-list-node"; export default class LinkedList { constructor(n) { @@ -12,7 +12,9 @@ export default class LinkedList { } else if (n instanceof Node) { this.root = n; } else { - throw new Error('LinkedList constructor was not called with a Node or Array as its argument.'); + throw new Error( + "LinkedList constructor was not called with a Node or Array as its argument.", + ); } } diff --git a/lists-and-trees/test/linked-list-node.spec.js b/lists-and-trees/test/linked-list-node.spec.js index f8425bd..c280341 100644 --- a/lists-and-trees/test/linked-list-node.spec.js +++ b/lists-and-trees/test/linked-list-node.spec.js @@ -1,27 +1,27 @@ /* eslint-disable prefer-arrow-callback */ -import { describe, it } from 'mocha'; +import { describe, it } from "mocha"; -import { expect } from 'chai'; -import Node from '../linked-list-node'; +import { expect } from "chai"; +import Node from "../linked-list-node"; -describe('Linked list Node class', function () { - it('should construct with passed data', function () { - const a = new Node('a'); +describe("Linked list Node class", function () { + it("should construct with passed data", function () { + const a = new Node("a"); - expect(a.getData()).to.equal('a'); + expect(a.getData()).to.equal("a"); }); - it('should allow to set next', function () { - const a = new Node('a'); - const b = new Node('b'); + it("should allow to set next", function () { + const a = new Node("a"); + const b = new Node("b"); a.setNext(b); - expect(a.getNext().getData()).to.equal('b'); + expect(a.getNext().getData()).to.equal("b"); }); - it('should set next to null by default', function () { - const a = new Node('a'); + it("should set next to null by default", function () { + const a = new Node("a"); a.setNext(); expect(a.getNext()).to.equal(null); diff --git a/lists-and-trees/test/linked-list.spec.js b/lists-and-trees/test/linked-list.spec.js index 5edba3c..fc75dae 100644 --- a/lists-and-trees/test/linked-list.spec.js +++ b/lists-and-trees/test/linked-list.spec.js @@ -1,77 +1,79 @@ /* global beforeEach */ /* eslint-disable prefer-arrow-callback */ -import { describe, it } from 'mocha'; +import { describe, it } from "mocha"; -import { expect } from 'chai'; -import LinkedList from '../linked-list'; -import Node from '../linked-list-node'; +import { expect } from "chai"; +import LinkedList from "../linked-list"; +import Node from "../linked-list-node"; -describe('Linked list class', function () { - describe('constructor', function () { - it('Should throw if constructor called w/wrong argument', function () { +describe("Linked list class", function () { + describe("constructor", function () { + it("Should throw if constructor called w/wrong argument", function () { expect(function () { - const foo = new LinkedList('foo'); // eslint-disable-line - }).to.throw('LinkedList constructor was not called with a Node or Array as its argument.'); + const foo = new LinkedList("foo"); // eslint-disable-line + }).to.throw( + "LinkedList constructor was not called with a Node or Array as its argument.", + ); }); - it('Should assign root if constructor called w/argument', function () { - const a = new Node('a'); + it("Should assign root if constructor called w/argument", function () { + const a = new Node("a"); const foo = new LinkedList(a); expect(foo.root).to.equal(a); - const b = new Node('b'); + const b = new Node("b"); const bar = new LinkedList([b]); expect(bar.root).to.equal(b); }); }); - describe('methods', function () { + describe("methods", function () { let a; let b; let c; beforeEach(function () { - a = new Node('a'); - b = new Node('b'); - c = new Node('c'); + a = new Node("a"); + b = new Node("b"); + c = new Node("c"); }); - it('should, provided with data, delete node from list', function () { + it("should, provided with data, delete node from list", function () { const foo = new LinkedList([a, b, c]); - foo.delete('b'); - expect(foo.walk()).to.deep.equal(['a', 'c']); + foo.delete("b"); + expect(foo.walk()).to.deep.equal(["a", "c"]); }); - it('should, provided with data, get node from list', function () { + it("should, provided with data, get node from list", function () { const foo = new LinkedList([a, b, c]); - expect(foo.get('b')).to.equal(b); + expect(foo.get("b")).to.equal(b); }); - it('should walk list, and return an array of data', function () { + it("should walk list, and return an array of data", function () { const foo = new LinkedList([a, b, c]); - expect(foo.walk()).to.deep.equal(['a', 'b', 'c']); + expect(foo.walk()).to.deep.equal(["a", "b", "c"]); }); - it('should, provided with prior data, insert a node', function () { + it("should, provided with prior data, insert a node", function () { const foo = new LinkedList([a, b, c]); - const x = new Node('x'); - foo.insert('b', x); - expect(foo.walk()).to.deep.equal(['a', 'b', 'x', 'c']); + const x = new Node("x"); + foo.insert("b", x); + expect(foo.walk()).to.deep.equal(["a", "b", "x", "c"]); }); - it('should push to the end of the list', function () { + it("should push to the end of the list", function () { const foo = new LinkedList([a, b, c]); - const x = new Node('x'); + const x = new Node("x"); foo.push(x); - expect(foo.walk()).to.deep.equal(['a', 'b', 'c', 'x']); + expect(foo.walk()).to.deep.equal(["a", "b", "c", "x"]); }); - it('should unshift to the front of the list', function () { + it("should unshift to the front of the list", function () { const foo = new LinkedList([a, b, c]); - const x = new Node('x'); + const x = new Node("x"); foo.unshift(x); - expect(foo.walk()).to.deep.equal(['x', 'a', 'b', 'c']); + expect(foo.walk()).to.deep.equal(["x", "a", "b", "c"]); }); }); }); diff --git a/misc/binary-search.js b/misc/binary-search.js index a5a23ca..308073a 100644 --- a/misc/binary-search.js +++ b/misc/binary-search.js @@ -14,4 +14,4 @@ export default function binarySearch(arr, item) { } } return -1; -}; +} diff --git a/misc/luhn.js b/misc/luhn.js index e13ab44..d50fb13 100644 --- a/misc/luhn.js +++ b/misc/luhn.js @@ -19,7 +19,7 @@ export default function luhn(number) { let isValid = false; // coercion - const arr = number.toString().split('').reverse(); + const arr = number.toString().split("").reverse(); const mapped = arr.map((item, index) => { item = parseInt(item, 10); // eslint-disable-line if ((index + 1) % 2 === 0) { @@ -27,20 +27,23 @@ export default function luhn(number) { } if (item >= 10) { // coercion - item = parseInt(item.toString().split('')[0], 10) + parseInt(item.toString().split('')[1], 10); // eslint-disable-line + item = + parseInt(item.toString().split("")[0], 10) + + parseInt(item.toString().split("")[1], 10); // eslint-disable-line } return item; }); let sum = 0; - for (let i = 1; i < mapped.length; i++) { // eslint-disable-line + for (let i = 1; i < mapped.length; i++) { + // eslint-disable-line // coercion sum += parseInt(mapped[i], 10); } // coercion - const sumArr = sum.toString().split(''); + const sumArr = sum.toString().split(""); // coercion const unitsDigit = parseInt(sumArr[sumArr.length - 1], 10); // coercion @@ -51,4 +54,4 @@ export default function luhn(number) { } return isValid; -}; +} diff --git a/misc/primes.js b/misc/primes.js index 8758aa4..30643ff 100644 --- a/misc/primes.js +++ b/misc/primes.js @@ -2,8 +2,7 @@ export default function primes(limit) { const primesArray = []; - outerLoop: - for (let i = 2; i <= limit; i++) { + outerLoop: for (let i = 2; i <= limit; i++) { if (i !== 2 && i % 2 === 0) { continue; } @@ -20,5 +19,5 @@ export default function primes(limit) { } return primesArray; -}; +} /* eslint-enable */ diff --git a/misc/test/binary-search.spec.js b/misc/test/binary-search.spec.js index 66743d7..de118b0 100644 --- a/misc/test/binary-search.spec.js +++ b/misc/test/binary-search.spec.js @@ -1,17 +1,17 @@ /* eslint-disable prefer-arrow-callback */ -import { describe, it } from 'mocha'; +import { describe, it } from "mocha"; -import { expect } from 'chai'; -import binarySearch from '../binary-search'; -import primes from '../primes'; +import { expect } from "chai"; +import binarySearch from "../binary-search"; +import primes from "../primes"; -describe('Binary search', function () { - it('should return index of the correct guess', function () { +describe("Binary search", function () { + it("should return index of the correct guess", function () { expect(binarySearch(primes(25), 17)).to.equal(6); }); - it('should return -1 if no feasible correct guess', function () { + it("should return -1 if no feasible correct guess", function () { expect(binarySearch(primes(25), 15)).to.equal(-1); }); }); diff --git a/misc/test/luhn.spec.js b/misc/test/luhn.spec.js index b9cf73f..9279e9f 100644 --- a/misc/test/luhn.spec.js +++ b/misc/test/luhn.spec.js @@ -1,17 +1,17 @@ /* eslint-disable prefer-arrow-callback */ -import { describe, it } from 'mocha'; +import { describe, it } from "mocha"; -import { expect } from 'chai'; -import luhn from '../luhn'; +import { expect } from "chai"; +import luhn from "../luhn"; -describe('Luhn algorithm', function () { - it('should return true for valid numbers', function () { +describe("Luhn algorithm", function () { + it("should return true for valid numbers", function () { expect(luhn(79927398713)).to.equal(true); expect(luhn(347136731693028)).to.equal(true); }); - it('should return false for invalid numbers', function () { + it("should return false for invalid numbers", function () { expect(luhn(79927398710)).to.equal(false); expect(luhn(79927398711)).to.equal(false); expect(luhn(79927398712)).to.equal(false); diff --git a/misc/test/primes.spec.js b/misc/test/primes.spec.js index 4e0aca8..554f323 100644 --- a/misc/test/primes.spec.js +++ b/misc/test/primes.spec.js @@ -1,12 +1,12 @@ /* eslint-disable prefer-arrow-callback */ -import { describe, it } from 'mocha'; +import { describe, it } from "mocha"; -import { expect } from 'chai'; -import primes from '../primes'; +import { expect } from "chai"; +import primes from "../primes"; -describe('Primes up to limit', function () { - it('should return array of primes up to limit', function () { +describe("Primes up to limit", function () { + it("should return array of primes up to limit", function () { expect(primes(25)).to.deep.equal([2, 3, 5, 7, 11, 13, 17, 19, 23]); }); }); diff --git a/sorting/binaryToDecimal.js b/sorting/binaryToDecimal.js index bb374e8..3a0108d 100644 --- a/sorting/binaryToDecimal.js +++ b/sorting/binaryToDecimal.js @@ -6,15 +6,15 @@ */ export default function binaryToDecimal(binary) { const str = binary.toString(); - const arr = str.split(''); + const arr = str.split(""); const rev = arr.reverse(); let decimal = 0; rev.forEach((value, index) => { - if (value === '1') { + if (value === "1") { decimal += 2 ** index; } }); return decimal; -}; +} diff --git a/sorting/bubbleSort.js b/sorting/bubbleSort.js index 6d5a8be..7c449f2 100644 --- a/sorting/bubbleSort.js +++ b/sorting/bubbleSort.js @@ -1,6 +1,6 @@ -import visit from './visit'; -import compare from './compare'; -import swap from './swap'; +import visit from "./visit"; +import compare from "./compare"; +import swap from "./swap"; export default function bubbleSort(data) { let sorted = data.slice(); diff --git a/sorting/compare.js b/sorting/compare.js index 0d73ba5..345389e 100644 --- a/sorting/compare.js +++ b/sorting/compare.js @@ -2,5 +2,4 @@ export default function compare(a, b) { if (a < b) return -1; if (a > b) return 1; return 0; -}; - +} diff --git a/sorting/insertionSort.js b/sorting/insertionSort.js index c8e6c1b..1ec08e2 100644 --- a/sorting/insertionSort.js +++ b/sorting/insertionSort.js @@ -1,6 +1,6 @@ -import visit from './visit'; -import compare from './compare'; -import swap from './swap'; +import visit from "./visit"; +import compare from "./compare"; +import swap from "./swap"; export default function insertionSort(data) { let sorted = data.slice(); diff --git a/sorting/ponySort.js b/sorting/ponySort.js index 76562c8..e8ebc90 100644 --- a/sorting/ponySort.js +++ b/sorting/ponySort.js @@ -1,9 +1,9 @@ /* eslint no-mixed-operators: 0 */ -import visit from './visit'; +import visit from "./visit"; -import compare from './compare'; -import swap from './swap'; +import compare from "./compare"; +import swap from "./swap"; export default function ponySort(data) { const sorted = data.slice(); diff --git a/sorting/sortByLessThanTally.js b/sorting/sortByLessThanTally.js index b8514ca..e1feb69 100644 --- a/sorting/sortByLessThanTally.js +++ b/sorting/sortByLessThanTally.js @@ -12,4 +12,4 @@ export default function (data) { } return [].concat(...sorted); -}; +} diff --git a/sorting/swap.js b/sorting/swap.js index bdb55c5..186de0b 100644 --- a/sorting/swap.js +++ b/sorting/swap.js @@ -7,4 +7,4 @@ export default function swap(data, a, b) { data[a] = memberB; return data; -}; +} diff --git a/sorting/tally.js b/sorting/tally.js index b662e5f..cf1c510 100644 --- a/sorting/tally.js +++ b/sorting/tally.js @@ -1,4 +1,4 @@ -import compare from './compare'; +import compare from "./compare"; export default function tally(data, callback) { const visited = []; @@ -32,7 +32,7 @@ export default function tally(data, callback) { return null; }); - const filtered = tallied.filter(item => item != null); + const filtered = tallied.filter((item) => item != null); if (callback) { return callback(filtered); diff --git a/sorting/test/binaryToDecimal.spec.js b/sorting/test/binaryToDecimal.spec.js index 3bb1f98..39b0766 100644 --- a/sorting/test/binaryToDecimal.spec.js +++ b/sorting/test/binaryToDecimal.spec.js @@ -1,15 +1,14 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import binaryToDecimal from '../binaryToDecimal'; +import binaryToDecimal from "../binaryToDecimal"; -describe('binary to decimal', () => { - it('should convert from binary representation to decimal', () => { +describe("binary to decimal", () => { + it("should convert from binary representation to decimal", () => { expect(binaryToDecimal(0)).to.equal(0); expect(binaryToDecimal(10111)).to.equal(23); expect(binaryToDecimal(101010)).to.equal(42); expect(binaryToDecimal(11111111)).to.equal(255); }); }); - diff --git a/sorting/test/bubbleSort.spec.js b/sorting/test/bubbleSort.spec.js index ef30d04..7a7a516 100644 --- a/sorting/test/bubbleSort.spec.js +++ b/sorting/test/bubbleSort.spec.js @@ -1,25 +1,25 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import bubbleSort from '../bubbleSort'; +import bubbleSort from "../bubbleSort"; -describe('bubble sort', () => { - it('should return the sorted array, from an input array of unique members', () => { +describe("bubble sort", () => { + it("should return the sorted array, from an input array of unique members", () => { const data = [3, 2, 6, 7, 8, 0]; const expected = [0, 2, 3, 6, 7, 8]; expect(bubbleSort(data)).to.deep.equal(expected); }); - it('should return the sorted array, from an input array of duplicate members', () => { + it("should return the sorted array, from an input array of duplicate members", () => { const data = [3, 3, 2, 2, 6, 6, 7, 7, 8, 8, 0, 0]; const expected = [0, 0, 2, 2, 3, 3, 6, 6, 7, 7, 8, 8]; expect(bubbleSort(data)).to.deep.equal(expected); }); - it('should return the sorted array, from an input array of unique and duplicate members', () => { + it("should return the sorted array, from an input array of unique and duplicate members", () => { const data = [3, 2, 2, 6, 6, 7, 8, 8, 0]; const expected = [0, 2, 2, 3, 6, 6, 7, 8, 8]; diff --git a/sorting/test/compare.spec.js b/sorting/test/compare.spec.js index d66b5ee..98f0c3f 100644 --- a/sorting/test/compare.spec.js +++ b/sorting/test/compare.spec.js @@ -1,20 +1,19 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import compare from '../compare'; +import compare from "../compare"; -describe('compare', () => { - it('should return -1 if a < b', () => { +describe("compare", () => { + it("should return -1 if a < b", () => { expect(compare(1, 2)).to.equal(-1); }); - it('should return 1 if a > b', () => { + it("should return 1 if a > b", () => { expect(compare(2, 1)).to.equal(1); }); - it('should return 0 if a === b', () => { + it("should return 0 if a === b", () => { expect(compare(1, 1)).to.equal(0); }); }); - diff --git a/sorting/test/insertionSort.spec.js b/sorting/test/insertionSort.spec.js index df732a1..9a0c679 100644 --- a/sorting/test/insertionSort.spec.js +++ b/sorting/test/insertionSort.spec.js @@ -1,25 +1,25 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import insertionSort from '../insertionSort'; +import insertionSort from "../insertionSort"; -describe('insertion sort', () => { - it('should return the sorted array, from an input array of unique members', () => { +describe("insertion sort", () => { + it("should return the sorted array, from an input array of unique members", () => { const data = [3, 2, 6, 7, 8, 0]; const expected = [0, 2, 3, 6, 7, 8]; expect(insertionSort(data)).to.deep.equal(expected); }); - it('should return the sorted array, from an input array of duplicate members', () => { + it("should return the sorted array, from an input array of duplicate members", () => { const data = [3, 3, 2, 2, 6, 6, 7, 7, 8, 8, 0, 0]; const expected = [0, 0, 2, 2, 3, 3, 6, 6, 7, 7, 8, 8]; expect(insertionSort(data)).to.deep.equal(expected); }); - it('should return the sorted array, from an input array of unique and duplicate members', () => { + it("should return the sorted array, from an input array of unique and duplicate members", () => { const data = [3, 2, 2, 6, 6, 7, 8, 8, 0]; const expected = [0, 2, 2, 3, 6, 6, 7, 8, 8]; diff --git a/sorting/test/ponySort.spec.js b/sorting/test/ponySort.spec.js index afb10b0..c22c57e 100644 --- a/sorting/test/ponySort.spec.js +++ b/sorting/test/ponySort.spec.js @@ -1,11 +1,11 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import ponySort from '../ponySort'; +import ponySort from "../ponySort"; -describe('pony sort', () => { - it('should not return the sorted array', () => { +describe("pony sort", () => { + it("should not return the sorted array", () => { const data = [3, 2, 6, 7, 8, 0]; const expected = [0, 2, 3, 6, 7, 8]; diff --git a/sorting/test/sortByLessThanTally.spec.js b/sorting/test/sortByLessThanTally.spec.js index 8082995..a0e3b3b 100644 --- a/sorting/test/sortByLessThanTally.spec.js +++ b/sorting/test/sortByLessThanTally.spec.js @@ -1,19 +1,35 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import sortByLessThanTally from '../sortByLessThanTally'; +import sortByLessThanTally from "../sortByLessThanTally"; -describe('sort by less than tally', () => { - it('should return the members sorted into place', () => { - const data = [[3, 3], [2, 4], [6, 2], [7, 1], [8, 0], [0, 5]]; +describe("sort by less than tally", () => { + it("should return the members sorted into place", () => { + const data = [ + [3, 3], + [2, 4], + [6, 2], + [7, 1], + [8, 0], + [0, 5], + ]; expect(sortByLessThanTally(data)).to.deep.equal([0, 2, 3, 6, 7, 8]); }); - it('should return multiple identical members sorted into place', () => { - const data = [[[3, 3], 3], [[2, 2], 4], [[6, 6], 2], [[7, 7], 1], [[8, 8], 0], [[0, 0], 5]]; + it("should return multiple identical members sorted into place", () => { + const data = [ + [[3, 3], 3], + [[2, 2], 4], + [[6, 6], 2], + [[7, 7], 1], + [[8, 8], 0], + [[0, 0], 5], + ]; - expect(sortByLessThanTally(data)).to.deep.equal([0, 0, 2, 2, 3, 3, 6, 6, 7, 7, 8, 8]); + expect(sortByLessThanTally(data)).to.deep.equal([ + 0, 0, 2, 2, 3, 3, 6, 6, 7, 7, 8, 8, + ]); }); }); diff --git a/sorting/test/swap.spec.js b/sorting/test/swap.spec.js index 2907570..e25d1aa 100644 --- a/sorting/test/swap.spec.js +++ b/sorting/test/swap.spec.js @@ -1,11 +1,11 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import swap from '../swap'; +import swap from "../swap"; -describe('swap', () => { - it('should mutate and return the array with swapped members at the defined indexes', () => { +describe("swap", () => { + it("should mutate and return the array with swapped members at the defined indexes", () => { const data = [0, 3, 2, 6, 7, 8]; const expected = [0, 2, 3, 6, 7, 8]; diff --git a/sorting/test/tally.spec.js b/sorting/test/tally.spec.js index a89d88e..bbc5030 100644 --- a/sorting/test/tally.spec.js +++ b/sorting/test/tally.spec.js @@ -1,20 +1,34 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import tally from '../tally'; +import tally from "../tally"; -describe('tally', () => { - it('should create a less than tally for single values', () => { +describe("tally", () => { + it("should create a less than tally for single values", () => { const data = [3, 2, 6, 7, 8, 0]; - const expected = [[[3], 3], [[2], 4], [[6], 2], [[7], 1], [[8], 0], [[0], 5]]; + const expected = [ + [[3], 3], + [[2], 4], + [[6], 2], + [[7], 1], + [[8], 0], + [[0], 5], + ]; expect(tally(data)).to.deep.equal(expected); }); - it('should create a less than tally for multiple values', () => { + it("should create a less than tally for multiple values", () => { const data = [3, 3, 2, 2, 6, 6, 7, 7, 8, 8, 0, 0]; - const expected = [[[3, 3], 3], [[2, 2], 4], [[6, 6], 2], [[7, 7], 1], [[8, 8], 0], [[0, 0], 5]]; + const expected = [ + [[3, 3], 3], + [[2, 2], 4], + [[6, 6], 2], + [[7, 7], 1], + [[8, 8], 0], + [[0, 0], 5], + ]; expect(tally(data)).to.deep.equal(expected); }); diff --git a/sorting/test/tallyAndSort.spec.js b/sorting/test/tallyAndSort.spec.js index 8e0d39e..266b6d6 100644 --- a/sorting/test/tallyAndSort.spec.js +++ b/sorting/test/tallyAndSort.spec.js @@ -1,26 +1,26 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import tally from '../tally'; -import sort from '../sortByLessThanTally'; +import tally from "../tally"; +import sort from "../sortByLessThanTally"; -describe('tally and sort', () => { - it('should return the sorted array, from an input array of unique members', () => { +describe("tally and sort", () => { + it("should return the sorted array, from an input array of unique members", () => { const data = [3, 2, 6, 7, 8, 0]; const expected = [0, 2, 3, 6, 7, 8]; expect(tally(data, sort)).to.deep.equal(expected); }); - it('should return the sorted array, from an input array of duplicate members', () => { + it("should return the sorted array, from an input array of duplicate members", () => { const data = [3, 3, 2, 2, 6, 6, 7, 7, 8, 8, 0, 0]; const expected = [0, 0, 2, 2, 3, 3, 6, 6, 7, 7, 8, 8]; expect(tally(data, sort)).to.deep.equal(expected); }); - it('should return the sorted array, from an input array of unique and duplicate members', () => { + it("should return the sorted array, from an input array of unique and duplicate members", () => { const data = [3, 2, 2, 6, 6, 7, 8, 8, 0]; const expected = [0, 2, 2, 3, 6, 6, 7, 8, 8]; diff --git a/sorting/test/visit.spec.js b/sorting/test/visit.spec.js index 303e0b3..afc09c1 100644 --- a/sorting/test/visit.spec.js +++ b/sorting/test/visit.spec.js @@ -1,15 +1,15 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import visit from '../visit'; +import visit from "../visit"; -describe('visit', () => { - it('should return the members at the defined indexes if no callback provided', () => { +describe("visit", () => { + it("should return the members at the defined indexes if no callback provided", () => { expect(visit([1, 2, 3], [0, 2])).to.deep.equal([1, 3]); }); - it('should return the return value of the callback if provided', () => { + it("should return the return value of the callback if provided", () => { expect(visit([1, 2, 3], [0, 2], (a, b) => a + b)).to.equal(4); }); }); diff --git a/sorting/test/visitAndCompare.spec.js b/sorting/test/visitAndCompare.spec.js index 48ead76..3d529a6 100644 --- a/sorting/test/visitAndCompare.spec.js +++ b/sorting/test/visitAndCompare.spec.js @@ -1,12 +1,12 @@ /* global describe, it */ -import { expect } from 'chai'; +import { expect } from "chai"; -import visit from '../visit'; -import compare from '../compare'; +import visit from "../visit"; +import compare from "../compare"; -describe('visit and compare', () => { - it('should return the result of comparing the specified members', () => { +describe("visit and compare", () => { + it("should return the result of comparing the specified members", () => { expect(visit([1, 2, 3], [0, 2], compare)).to.equal(-1); }); }); diff --git a/sorting/visit.js b/sorting/visit.js index f0766c7..987c2f5 100644 --- a/sorting/visit.js +++ b/sorting/visit.js @@ -10,4 +10,4 @@ export default function (arr, indexes, callback) { } return members; -}; +} From 86c75b5fd453790861f02077654a5ffc2e5ee6aa Mon Sep 17 00:00:00 2001 From: Jerome Covington Date: Wed, 7 Feb 2024 16:26:05 -0500 Subject: [PATCH 5/5] add test workflow --- .github/workflows/tests.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..4c263e7 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,21 @@ +name: Node.js Tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + - run: npm install + - run: npm run prettier + - run: npm test