Skip to content

Commit

Permalink
2023-08-16T14:06:59.054Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Aug 16, 2023
1 parent a868d1e commit a3f19eb
Show file tree
Hide file tree
Showing 43 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions src/028-mutability/084-narrowing-in-different-scopes.problem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect, it } from "vitest";

const findUsersByName = (
searchParams: { name?: string },
users: {
id: string;
name: string;
}[],
) => {
if (searchParams.name) {
return users.filter((user) => user.name.includes(searchParams.name));
}

return users;
};

it("Should find the exact name", () => {
const result = findUsersByName(
{
name: "Bob",
},
[
{
id: "1",
name: "Bob",
},
{
id: "2",
name: "Alice",
},
],
);

expect(result).toEqual([
{
id: "1",
name: "Bob",
},
]);

type test = Expect<Equal<typeof result, { id: string; name: string }[]>>;
});
43 changes: 43 additions & 0 deletions src/028-mutability/084-narrowing-in-different-scopes.solution.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect, it } from "vitest";

const findUsersByName = (
searchParams: { name?: string },
users: {
id: string;
name: string;
}[],
) => {
let name = searchParams.name;
if (name) {
return users.filter((user) => user.name.includes(name));
}

return users;
};

it("Should find the exact name", () => {
const result = findUsersByName(
{
name: "Bob",
},
[
{
id: "1",
name: "Bob",
},
{
id: "2",
name: "Alice",
},
],
);

expect(result).toEqual([
{
id: "1",
name: "Bob",
},
]);

type test = Expect<Equal<typeof result, { id: string; name: string }[]>>;
});
43 changes: 43 additions & 0 deletions src/028-mutability/084-narrowing-in-different-scopes.solution.2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect, it } from "vitest";

const findUsersByName = (
searchParams: { name?: string },
users: {
id: string;
name: string;
}[],
) => {
const name = searchParams.name;
if (name) {
return users.filter((user) => user.name.includes(name));
}

return users;
};

it("Should find the exact name", () => {
const result = findUsersByName(
{
name: "Bob",
},
[
{
id: "1",
name: "Bob",
},
{
id: "2",
name: "Alice",
},
],
);

expect(result).toEqual([
{
id: "1",
name: "Bob",
},
]);

type test = Expect<Equal<typeof result, { id: string; name: string }[]>>;
});
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit a3f19eb

Please sign in to comment.