[ya-day1] tshortChooser solution for base case

main
Vasily Guzov 1 year ago
parent 17f0be347b
commit 46779a7da5

@ -3,6 +3,31 @@ import { tiShortChoser } from "./tiShortChoser.ts";
describe("tiShortChoser", () => { describe("tiShortChoser", () => {
it("tiShortChoser 6, 2, 7, 3", () => { it("tiShortChoser 6, 2, 7, 3", () => {
expect(tiShortChoser(6, 2, 7, 3)).toEqual([3, 4]); expect(tiShortChoser(6, 2, 7, 3)).toEqual("3 4");
});
it("tiShortChoser 6, 6, 7, 3", () => {
expect(tiShortChoser(6, 6, 7, 3)).toEqual("2 4");
});
it("tiShortChoser 3, 3, 5, 5", () => {
expect(tiShortChoser(3, 3, 5, 5)).toEqual("2 2");
});
it("tiShortChoser 1, 1, 99, 99", () => {
expect(tiShortChoser(1, 1, 99, 99)).toEqual("2 2");
});
it("tiShortChoser 5, 7, 7, 3", () => {
expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3");
});
it("tiShortChoser 5, 7, 7, 3", () => {
expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3");
});
it("tiShortChoser 5, 0, 7, 3", () => {
expect(tiShortChoser(5, 0, 7, 3)).toEqual("1 4");
});
it("tiShortChoser 0, 1, 7, 3", () => {
expect(tiShortChoser(0, 1, 17, 50)).toEqual("1 18");
}); });
}); });

@ -4,5 +4,14 @@ export function tiShortChoser(
sBlue: number, sBlue: number,
sRed: number, sRed: number,
) { ) {
return [3, 4]; let tishort = tBlue > tRed ? tRed + 1 : tBlue + 1;
let socks = sBlue > sRed ? sRed + 1 : sBlue + 1;
if (tBlue === tRed) tishort = tRed + 1;
if (sBlue === sRed) socks = sRed + 1;
if (tBlue === tRed && tBlue === 1) tishort = 2;
if (sBlue === sRed && sBlue === 1) socks = 2;
return [tishort, socks].join(" ");
} }

Loading…
Cancel
Save