diff --git a/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.test.ts b/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.test.ts index 7d18d22..aaeebdd 100644 --- a/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.test.ts +++ b/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.test.ts @@ -1,12 +1,8 @@ test("dummy test", () => undefined); -import { - OriginalTeam, - ExpectedTeam, - originalTeamToExpectedTeam, - originalArrayToExpectedArray, - originalTeamToExpectedTeamDeep, -} from "./immutability"; +/* + +import { OriginalTeam, ExpectedTeam } from "./immutability"; // Задание 1 test("team to team", () => { @@ -22,7 +18,7 @@ test("team to team", () => { roster: 25, }; - expect(originalTeamToExpectedTeam(originalTeam)).toStrictEqual(expectedTeam); + expect(originalTeamToExpectedTeam(originalTeam)).toBe(expectedTeam); }); // Задание 2 @@ -30,12 +26,11 @@ test("array to array", () => { const originalArray = Object.freeze([1, 2, 3, 4]); const expectedArray = ["two", 3, 4, 5]; - expect(originalArrayToExpectedArray(originalArray)).toStrictEqual( - expectedArray - ); + + expect(originalArrayToExpectedArray(originalArray)).toBe(expectedArray); }); -// // Задание 3 +// Задание 3 test("team to team deep", () => { const originalTeam = Object.freeze({ name: "Tampa Bay Roosters", @@ -53,5 +48,7 @@ test("team to team deep", () => { }, }; - expect(originalTeamToExpectedTeamDeep(originalTeam)).toEqual(expectedTeam); + expect(originalTeamToExpectedTeam(originalTeam)).toEqual(expectedTeam); }); + +*/ diff --git a/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.ts b/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.ts index cd025ea..b802a08 100644 --- a/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.ts +++ b/lessons/module2/4_FunctionalProgramming_Old/homework/immutability.ts @@ -1,49 +1,39 @@ // // Задание 1 -export type OriginalTeam = { - size: number; - name: string; - league: string; -}; +// export type OriginalTeam = { +// size: number; +// name: string; +// league: string; +// }; -export type ExpectedTeam = { - name: string; - league: string; - roster: number; -}; +// export type ExpectedTeam = { +// name: string; +// league: string; +// roster: number; +// }; -export const originalTeamToExpectedTeam = ( - originalTeam: OriginalTeam -): ExpectedTeam => { - const { league } = originalTeam; - return { - league: league, - roster: 25, - name: "New York Badgers", - }; -}; +// export const originalTeamToExpectedTeam = ( +// originalTeam: OriginalTeam +// ): ExpectedTeam => { +// // +// }; // // Задание 2 -type SomeArray = ReadonlyArray; +// type SomeArray = Array; -export const originalArrayToExpectedArray = ( - originalArray: SomeArray -): SomeArray => { - const newArray = ["two", ...originalArray.slice(2), 5]; - return newArray; -}; +// const originalArrayToExpectedArray = (originalArray: SomeArray): SomeArray => { +// // +// }; // // Задание 3 -export type Team = { - name: string; - captain: { - name: string; - age: number; - }; -}; +// export type Team = { +// name: string; +// captain: { +// name: string; +// age: number; +// }; +// }; -export const originalTeamToExpectedTeamDeep = (originalTeam: Team): Team => { - const newObj = JSON.parse(JSON.stringify(originalTeam)); - newObj.captain.age = 28; - return newObj; -}; +// export const originalTeamToExpectedTeam = (originalTeam: Team): Team => { +// // +// }; diff --git a/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.test.ts b/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.test.ts index 7cfd1db..cbf2774 100644 --- a/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.test.ts +++ b/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.test.ts @@ -1,35 +1,37 @@ test("dummy test", () => undefined); +/* + import { getTopName, Team, QsObj, createQs, parseQs } from "./pureFunctions"; test("it works", () => expect(true).toBe(true)); -test("getTopName", () => { - const teams: Team[] = [ - { name: "Lions", score: 5 }, - { name: "Tigers", score: 4 }, - { name: "Bears", score: 6 }, - { name: "Monkeys", score: 2 }, - ]; - - expect(getTopName(teams)).toBe("Bears"); -}); - -test("createQs", () => { - const qsObj: QsObj = { - page: "2", - pageSize: "10", - total: "205", - somethingElse: "value", - }; - - expect(createQs(qsObj)).toBe( - "?page=2&pageSize=10&total=205&somethingElse=value" - ); -}); - -test("parseQs", () => { - const qs = "?page=2&pageSize=10&total=205&somethingElse=value"; +// test("getTopName", () => { +// const teams: Team[] = [ +// { name: "Lions", score: 5 }, +// { name: "Tigers", score: 4 }, +// { name: "Bears", score: 6 }, +// { name: "Monkeys", score: 2 }, +// ]; + +// expect(getTopName(teams)).toBe("Bears"); +// }); + +// test("createQs", () => { +// const qsObj: QsObj = { +// page: "2", +// pageSize: "10", +// total: "205", +// somethingElse: "value", +// }; + +// expect(createQs(qsObj)).toBe( +// "?page=2&pageSize=10&total=205&somethingElse=value" +// ); +// }); + +// test("parseQs", () => { +// const qs = "?page=2&pageSize=10&total=205&somethingElse=value"; expect(parseQs(qs)).toEqual({ page: "2", @@ -38,3 +40,5 @@ test("parseQs", () => { somethingElse: "value", }); }); + +*/ diff --git a/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.ts b/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.ts index 8d05f86..98667d4 100644 --- a/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.ts +++ b/lessons/module2/4_FunctionalProgramming_Old/homework/pureFunctions.ts @@ -1,13 +1,9 @@ // // Задание 1 -export type Team = { name: string; score: number }; +// export type Team = { name: string; score: number }; -export const getTopName = (teams: Team[]): string => { - let topTeam = teams[0]; - teams.forEach((value, index) => - value.score > topTeam.score ? (topTeam = teams[index]) : undefined - ); - return topTeam.name; -}; +// export const getTopName = (teams: Team[]): string => { +// // +// }; // // Задание 2 export type QsObj = Record< @@ -15,25 +11,12 @@ export type QsObj = Record< string | number | boolean | string[] | number[] | boolean[] >; -export const createQs = (qsObj: QsObj): string => { - return ( - "?" + - Object.keys(qsObj) - .map((key) => { - return `${key}=${qsObj[key]}`; - }) - .join("&") - ); -}; +// export const createQs = (qsObj: QsObj): string => { +// // +// }; // // Задание 3 -export const parseQs = (qs: string): QsObj => { - const pairs = (qs[0] === "?" ? qs.substr(1) : qs).split("&"); - const result: QsObj = {}; - pairs.forEach((value, index) => { - const insertingValue = value.split("="); - result[insertingValue[0]] = insertingValue[1]; - }); - return result; -}; +// export const parseQs = (qs: string): QsObj => { +// // +// };