diff --git a/lib/tiShortChoser/tiShortChoser.test.ts b/lib/tiShortChoser/tiShortChoser.test.ts index 13d5731..f0952a7 100644 --- a/lib/tiShortChoser/tiShortChoser.test.ts +++ b/lib/tiShortChoser/tiShortChoser.test.ts @@ -63,5 +63,8 @@ describe("tiShortChoser", () => { it("____ 1000, 1, 1, 1000 ", () => { expect(tiShortChoser(1000, 1, 1, 1000)).toEqual("1001 1"); }); + it("1, 0, 1, 0 ", () => { + expect(tiShortChoser(1, 0, 1, 0)).toEqual("1 1"); + }); }); diff --git a/lib/tiShortChoser/tiShortChoser.ts b/lib/tiShortChoser/tiShortChoser.ts index 5721ea8..846b218 100644 --- a/lib/tiShortChoser/tiShortChoser.ts +++ b/lib/tiShortChoser/tiShortChoser.ts @@ -10,35 +10,41 @@ export function tiShortChoser( const isEquaal = tB + sB === tR + sR; const tIsEquale = tB === tR && tB > 0; const sIsEquale = sB === sR && sB > 0; + const isBlue = tB === sB && !tIsEquale && !sIsEquale; + const isRed = tR === sR && !tIsEquale && !sIsEquale; if (blueIsGrater) { - tishort = tR + 1; - socks = sR + 1; + tishort = sIsEquale && !isEquaal ? 1 : tR + 1; + socks = tIsEquale || isEquaal ? 1 : sR + 1; } else { - tishort = tB + 1; - socks = sB + 1; - } - - if (tIsEquale || isEquaal) { - tishort = tB + 1; - socks = 1; + tishort = sIsEquale && !isEquaal ? 1 : tB + 1; + socks = tIsEquale || isEquaal ? 1 : sB + 1; } - if (sIsEquale && !isEquaal) { - tishort = 1; - socks = sB + 1; - } if (tB === 0 || tR === 0) { tishort = 1; socks = tB === 0 ? sB + 1 : sR + 1; } - if (sB === 0 || sR === 0) { socks = 1; tishort = sB === 0 ? tB + 1 : tR + 1; } + if (isRed) { + tishort = tR + 1; + socks = 1; + } + + if (isBlue) { + tishort = tB + 1; + socks = 1; + } + + if (isBlue && isRed && (tB !== 0 || sB !== 0)) { + tishort = 2; + socks = 1; + } return [tishort, socks].join(" "); }