challenge ctci-random-note
This commit is contained in:
parent
3b7d0b4574
commit
4ef3e01ab5
5 changed files with 61 additions and 2 deletions
|
|
@ -9,7 +9,9 @@
|
||||||
"build+start": "npm run build && npm run start",
|
"build+start": "npm run build && npm run start",
|
||||||
"build:watch": "tsc -w -p tsconfig.json",
|
"build:watch": "tsc -w -p tsconfig.json",
|
||||||
"test:watch": "node --import tsx --test --watch **/**/*.spec.ts",
|
"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": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import {describe, it, skip} from 'node:test';
|
||||||
import * as assert from "node:assert";
|
import * as assert from "node:assert";
|
||||||
import {findHighestHourglassSum} from "./2d-array";
|
import {findHighestHourglassSum} from "./2d-array";
|
||||||
import {Matrix} from "./matrix";
|
import {Matrix} from "./matrix";
|
||||||
describe("2D Array", () => {
|
describe("2D Array", () => {
|
||||||
describe("findHighestHourglassSum", () => {
|
describe("findHighestHourglassSum", () => {
|
||||||
it("should return 0 if the matrix is empty", () => {
|
it("should return 0 if the matrix is empty", () => {
|
||||||
assert.equal(findHighestHourglassSum(new Matrix([])), 0);
|
assert.equal(findHighestHourglassSum(new Matrix([])), 0);
|
||||||
|
|
|
||||||
36
src/ctci-ransom-note/ctci-ransom-note.spec.ts
Normal file
36
src/ctci-ransom-note/ctci-ransom-note.spec.ts
Normal file
|
|
@ -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");
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
21
src/ctci-ransom-note/ctci-ransom-note.ts
Normal file
21
src/ctci-ransom-note/ctci-ransom-note.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
export function checkMagazine(magazine: Array<string>, note: Array<string>): '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'
|
||||||
|
}
|
||||||
0
src/new-year-chaos/new-year-chaos.ts
Normal file
0
src/new-year-chaos/new-year-chaos.ts
Normal file
Loading…
Add table
Add a link
Reference in a new issue