diff --git a/package.json b/package.json index ba8abc6..def0901 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,9 @@ "build+start": "npm run build && npm run start", "build:watch": "tsc -w -p tsconfig.json", "test:watch": "node --import tsx --test --watch **/**/*.spec.ts", - "test": "node --import tsx --test **/**/*.spec.ts" + "test:watch:only": "node --import tsx --test --test-only --watch **/**/*.spec.ts", + "test": "node --import tsx --test **/**/*.spec.ts", + "test:only": "node --import tsx --test --test-only **/**/*.spec.ts" }, "author": "", "license": "ISC", diff --git a/src/2d-array/2d-array.spec.ts b/src/2d-array/2d-array.spec.ts index 801728f..586a845 100644 --- a/src/2d-array/2d-array.spec.ts +++ b/src/2d-array/2d-array.spec.ts @@ -2,7 +2,7 @@ import {describe, it, skip} from 'node:test'; import * as assert from "node:assert"; import {findHighestHourglassSum} from "./2d-array"; import {Matrix} from "./matrix"; -describe("2D Array", () => { +describe("2D Array", () => { describe("findHighestHourglassSum", () => { it("should return 0 if the matrix is empty", () => { assert.equal(findHighestHourglassSum(new Matrix([])), 0); diff --git a/src/ctci-ransom-note/ctci-ransom-note.spec.ts b/src/ctci-ransom-note/ctci-ransom-note.spec.ts new file mode 100644 index 0000000..3ff30a0 --- /dev/null +++ b/src/ctci-ransom-note/ctci-ransom-note.spec.ts @@ -0,0 +1,36 @@ +import {describe, it} from "node:test"; +import assert = require("node:assert"); +import {checkMagazine} from "./ctci-ransom-note"; + +describe("Ctci Ransom Note", () => { + describe("checkMagazine", () => { + it("if note is empty should return Yes", () => { + assert.deepStrictEqual(checkMagazine(["bla", "ble", "bli"], []), "Yes"); + }) + + it("if magazine is empty and note have words should return No", () => { + assert.deepStrictEqual(checkMagazine([], ["bla", "ble", "bli"]), "No"); + }) + + it("Yes case", () => { + assert.deepStrictEqual(checkMagazine(["give", "me", "one", "grand" ,"today" ,"night"], ["give", "one", "grand", "today"]), "Yes"); + }) + + it("No case due case-sensitive in magazines", () => { + assert.deepStrictEqual(checkMagazine(["give", "me", "one", "Grand" ,"today" ,"night"], ["give", "one", "grand", "today"]), "No"); + }) + + it("No case due case-sensitive in note", () => { + assert.deepStrictEqual(checkMagazine(["give", "me", "one", "grand" ,"today" ,"night"], ["give", "one", "Grand", "today"]), "No"); + }) + + it("No case for lack of duplicated words", () => { + assert.deepStrictEqual(checkMagazine(["two", "times", "three", "is" ,"not" ,"four"], ["two", "times", "two", "is", "four"]), "No"); + }) + + it("No case", () => { + assert.deepStrictEqual(checkMagazine(["ive", "got", "a", "lovely" ,"bunch" ,"of", "coconuts"], ["ive", "got", "some", "coconuts"]), "No"); + }) + + }); +}) \ No newline at end of file diff --git a/src/ctci-ransom-note/ctci-ransom-note.ts b/src/ctci-ransom-note/ctci-ransom-note.ts new file mode 100644 index 0000000..88f9610 --- /dev/null +++ b/src/ctci-ransom-note/ctci-ransom-note.ts @@ -0,0 +1,21 @@ +export function checkMagazine(magazine: Array, note: Array): 'Yes' | 'No' { + + if(magazine.length === 0 && note.length > 0) { + return 'No' + } + + if(note.length === 0) { + return 'Yes' + } + + for(const n of note) { + const index = magazine.indexOf(n); + if(index > -1) { + magazine.splice(index, 1) + } else { + return 'No' + } + } + + return 'Yes' +} \ No newline at end of file diff --git a/src/new-year-chaos/new-year-chaos.ts b/src/new-year-chaos/new-year-chaos.ts new file mode 100644 index 0000000..e69de29