diff --git a/.yarn/cache/fsevents-patch-8f8bff7336-8.zip b/.yarn/cache/fsevents-patch-8f8bff7336-8.zip deleted file mode 100644 index 8043946..0000000 Binary files a/.yarn/cache/fsevents-patch-8f8bff7336-8.zip and /dev/null differ diff --git a/.yarn/cache/http-cache-semantics-npm-4.1.0-860520a31f-974de94a81.zip b/.yarn/cache/http-cache-semantics-npm-4.1.0-860520a31f-974de94a81.zip deleted file mode 100644 index ed85c1c..0000000 Binary files a/.yarn/cache/http-cache-semantics-npm-4.1.0-860520a31f-974de94a81.zip and /dev/null differ diff --git a/.yarn/cache/http-cache-semantics-npm-4.1.1-1120131375-83ac0bc60b.zip b/.yarn/cache/http-cache-semantics-npm-4.1.1-1120131375-83ac0bc60b.zip new file mode 100644 index 0000000..19f1e0a Binary files /dev/null and b/.yarn/cache/http-cache-semantics-npm-4.1.1-1120131375-83ac0bc60b.zip differ diff --git a/.yarn/cache/resolve-patch-2a6955419f-6fd799f282.zip b/.yarn/cache/resolve-patch-3775f38cdc-6fd799f282.zip similarity index 100% rename from .yarn/cache/resolve-patch-2a6955419f-6fd799f282.zip rename to .yarn/cache/resolve-patch-3775f38cdc-6fd799f282.zip diff --git a/.yarn/cache/resolve-patch-b31813b232-e9dbca7860.zip b/.yarn/cache/resolve-patch-6937e030b1-e9dbca7860.zip similarity index 100% rename from .yarn/cache/resolve-patch-b31813b232-e9dbca7860.zip rename to .yarn/cache/resolve-patch-6937e030b1-e9dbca7860.zip diff --git a/.yarn/cache/typescript-patch-8adb042441-301459fc3e.zip b/.yarn/cache/typescript-patch-5b3c915f01-563a0ef47a.zip similarity index 59% rename from .yarn/cache/typescript-patch-8adb042441-301459fc3e.zip rename to .yarn/cache/typescript-patch-5b3c915f01-563a0ef47a.zip index e060c93..902a50c 100644 Binary files a/.yarn/cache/typescript-patch-8adb042441-301459fc3e.zip and b/.yarn/cache/typescript-patch-5b3c915f01-563a0ef47a.zip differ diff --git a/2023/warm-up/square-root/square-root.js b/2023/warm-up/square-root/square-root.js new file mode 100644 index 0000000..2130a7b --- /dev/null +++ b/2023/warm-up/square-root/square-root.js @@ -0,0 +1,29 @@ +const squareRoot = (num) => { + if (num <= 2) { + return num; + } + + let left = 2; + let right = Math.floor(num / 2); + + while (left <= right) { + const middle = Math.floor((left + right) / 2); + const res = middle * middle; + + if (res === num) { + return middle; + } + + if (res < num) { + left = middle + 1; + } + + if (res > num) { + right = middle - 1; + } + } + + return Math.floor(right); +}; + +module.exports = squareRoot; diff --git a/2023/warm-up/square-root/square-root.spec.js b/2023/warm-up/square-root/square-root.spec.js new file mode 100644 index 0000000..47fc96f --- /dev/null +++ b/2023/warm-up/square-root/square-root.spec.js @@ -0,0 +1,32 @@ +const squareRoot = require("./square-root"); +describe("should find the clothest square root", () => { + it("returns 2 for 4", () => { + const res = squareRoot(4); + + expect(res).toBe(2); + }); + + it("calculates for 2", () => { + const res = squareRoot(2); + + expect(res).toBe(2); + }); + + it("calculates for 5", () => { + const res = squareRoot(5); + + expect(res).toBe(Math.floor(Math.sqrt(5))); + }); + + it("calculates for 6", () => { + const res = squareRoot(6); + + expect(res).toBe(Math.floor(Math.sqrt(6))); + }); + + it("calculates for 10", () => { + const res = squareRoot(10); + + expect(res).toBe(Math.floor(Math.sqrt(10))); + }); +}); diff --git a/yarn.lock b/yarn.lock index 9e72a01..10c2107 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2270,7 +2270,7 @@ __metadata: "fsevents@patch:fsevents@^2.1.2#~builtin": version: 2.1.3 - resolution: "fsevents@patch:fsevents@npm%3A2.1.3#~builtin::version=2.1.3&hash=31d12a" + resolution: "fsevents@patch:fsevents@npm%3A2.1.3#~builtin::version=2.1.3&hash=18f3a7" dependencies: node-gyp: latest conditions: os=darwin @@ -2497,9 +2497,9 @@ __metadata: linkType: hard "http-cache-semantics@npm:^4.1.0": - version: 4.1.0 - resolution: "http-cache-semantics@npm:4.1.0" - checksum: 974de94a81c5474be07f269f9fd8383e92ebb5a448208223bfb39e172a9dbc26feff250192ecc23b9593b3f92098e010406b0f24bd4d588d631f80214648ed42 + version: 4.1.1 + resolution: "http-cache-semantics@npm:4.1.1" + checksum: 83ac0bc60b17a3a36f9953e7be55e5c8f41acc61b22583060e8dedc9dd5e3607c823a88d0926f9150e571f90946835c7fe150732801010845c72cd8bbff1a236 languageName: node linkType: hard @@ -4595,14 +4595,14 @@ __metadata: "resolve@patch:resolve@1.1.7#~builtin": version: 1.1.7 - resolution: "resolve@patch:resolve@npm%3A1.1.7#~builtin::version=1.1.7&hash=3bafbf" + resolution: "resolve@patch:resolve@npm%3A1.1.7#~builtin::version=1.1.7&hash=07638b" checksum: e9dbca78600ae56835c43a09f1276876c883e4b4bbd43e2683fa140671519d2bdebeb1c1576ca87c8c508ae2987b3ec481645ac5d3054b0f23254cfc1ce49942 languageName: node linkType: hard "resolve@patch:resolve@^1.10.0#~builtin, resolve@patch:resolve@^1.15.1#~builtin, resolve@patch:resolve@^1.3.2#~builtin": version: 1.17.0 - resolution: "resolve@patch:resolve@npm%3A1.17.0#~builtin::version=1.17.0&hash=c3c19d" + resolution: "resolve@patch:resolve@npm%3A1.17.0#~builtin::version=1.17.0&hash=07638b" dependencies: path-parse: ^1.0.6 checksum: 6fd799f282ddf078c4bc20ce863e3af01fa8cb218f0658d9162c57161a2dbafe092b13015b9a4c58d0e1e801cf7aa7a4f13115fea9db98c3f9a0c43e429bad6f @@ -5411,11 +5411,11 @@ __metadata: "typescript@patch:typescript@^4.8.4#~builtin": version: 4.8.4 - resolution: "typescript@patch:typescript@npm%3A4.8.4#~builtin::version=4.8.4&hash=0102e9" + resolution: "typescript@patch:typescript@npm%3A4.8.4#~builtin::version=4.8.4&hash=a1c5e5" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 301459fc3eb3b1a38fe91bf96d98eb55da88a9cb17b4ef80b4d105d620f4d547ba776cc27b44cc2ef58b66eda23fe0a74142feb5e79a6fb99f54fc018a696afa + checksum: 563a0ef47abae6df27a9a3ab38f75fc681f633ccf1a3502b1108e252e187787893de689220f4544aaf95a371a4eb3141e4a337deb9895de5ac3c1ca76430e5f0 languageName: node linkType: hard