diff --git a/coverage/algorithms/add-component.mjs.html b/coverage/algorithms/add-component.mjs.html new file mode 100644 index 0000000..37613e2 --- /dev/null +++ b/coverage/algorithms/add-component.mjs.html @@ -0,0 +1,253 @@ + + + + +
++ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | import fs from "fs"; +import path from "path"; + +const defaultPath = "./lib/"; + +const componentFolderPath = process.argv[3] ? process.argv[3] : defaultPath; +const componentName = process.argv[2]; + +if (!componentName) { + console.error("Please provide a module name."); + process.exit(1); +} + +const folderPath = path.join(componentFolderPath, componentName); +const componentFilePath = path.join(folderPath, `${componentName}.ts`); +const testFile = path.join(folderPath, `${componentName}.test.ts`); +const indexPath = path.join(folderPath, "index.ts"); + +if (!fs.existsSync(folderPath)) { + fs.mkdirSync(folderPath, { recursive: true }); +} + +const componentContent = `export function ${componentName}() { + //your code here +}; +`; + +fs.writeFileSync(componentFilePath, componentContent); + +const testContent = `import { describe, it, expect } from "vitest"; +import { ${componentName} } from "./${componentName}.ts"; + +describe("${componentName}", () => { + let sortedArray = [-12, 1, 4, 6, 22]; + + it("${componentName}", () => { + expect(${componentName}(sortedArray, 4)).toBe(2); + }); + + it("${componentName}", () => { + expect(${componentName}(sortedArray, 3)).toBe(-1); + }); +}); +`; + +fs.writeFileSync(testFile, testContent); + +const indexContent = `import { ${componentName} } from "./${componentName}"; + +export default ${componentName}; +`; + +fs.writeFileSync(indexPath, indexContent); + +console.log(`Component ${componentName} created successfully at ${folderPath}`); + + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| add-component.mjs | +
+
+ |
+ 0% | +0/55 | +0% | +0/1 | +0% | +0/1 | +0% | +0/55 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 | 1x + +2x +2x + +2x + +3x +3x + + +3x +1x +1x + + + +3x +1x + +1x +1x +1x +3x + + +1x +1x + | export function binarySearch(sortedNumbers: number[], n: number) {
+ // Определяем точки начала и конца поиска
+ let start = 0;
+ let end = sortedNumbers.length;
+
+ while (start < end) {
+ // Находим элемент в середине массива
+ const middle = Math.floor((start + end) / 2);
+ const value = sortedNumbers[middle];
+
+ // Сравниваем аргумент со значением в середине массива
+ if (n === value) {
+ return middle;
+ }
+
+ // Если аргумент меньше, чем серединное значение, разделяем массив пополам
+ // Теперь конец массива — это его бывшая середина
+ if (n < value) {
+ end = middle;
+ // Иначе началом массива становится элемент, идущий сразу за «серединой»
+ } else {
+ start = middle + 1;
+ }
+ }
+
+ // если искомое число не найдено, возвращаем -1
+ return -1;
+}
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| binarySearch.ts | +
+
+ |
+ 100% | +17/17 | +100% | +6/6 | +100% | +1/1 | +100% | +17/17 | +
| index.ts | +
+
+ |
+ 0% | +0/1 | +0% | +0/1 | +0% | +0/1 | +0% | +0/1 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 | + | export * from "./binarySearch";
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 | + + + + + + + + + + + + | // We want to create a function that will add numbers together when called in succession. + +export default function add(x: number): any { + const fn = (y: number) => add(x + y); + fn.valueOf = () => x; + return fn; +} + +const seven = add(1)(2)(4); +console.log(seven == 7, 'expect 7') + +console.log(+add(1)(2), 'expect 3') + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | export function duplicateEncode(word: string) { + let res = ""; + let i = 0; + + while (i < word.length) { + const char = word[i]; + + const firstIndex = word.indexOf(char) + const lastIndex = word.lastIndexOf(char) + + if (firstIndex !== lastIndex) { + res += ")" + } else { + res += "(" + } + + i++ + } + + return res; +} + +export function duplicateEncode1(word: string) { + return word + .toLowerCase() + .split('') + .map((a, _, w) => { + return w.indexOf(a) == w.lastIndexOf(a) ? '(' : ')' + }) + .join('') +} + +console.log( + duplicateEncode("din"), "(((" +) +console.log( + duplicateEncode("recede"), "()()()" +) +console.log( + duplicateEncode("Success"), ")())())" +) +console.log( + duplicateEncode("(( @"), "))((" +) + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 | + + + + + + + + + + + + + + | function solution1(str: string, ending: string): boolean { + if (ending === "") return true; + const startIndex = str.length - ending.length; + const subStr = str.substring(startIndex); + return subStr === ending; +} + +export function bestSolution(str: string, ending: string): boolean { + return str.endsWith(ending); +} + +console.log(solution1("abcde", "cde"), true); +console.log(solution1("abcde", "abs"), false); +console.log(solution1("abcde", ""), true); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 | + + + + + + + + + + + + + + + + + + + + + + + + + | export function factorial(n) { + let result = 1; + for (let i = n; i > 1; i--) { + result *= i; + } + return result; +} + +export function factorialRecursive(n) { + if (n < 2) { + return 1; + } + + return n * factorialRecursive(n - 1); +} + +// --------------------------- TESTS --------------------------------------- + +console.time("factorial time: "); +factorial(1000); +console.timeLog("factorial time: "); + +console.time("recursive factorial time: "); +factorialRecursive(1000); +console.timeLog("recursive factorial time: "); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 | + + + + + + + + + + + + + + + + | // https://github.com/yangzj1992/FE-Questions/blob/master/codewars/5541f58a944b85ce6d00006a.Product%20of%20consecutive%20Fib%20numbers/Product%20of%20consecutive%20Fib%20numbers.md +export function fib(prod: number) { + let n = 0; + let nPlus = 1; + + while (n * nPlus < prod) { + nPlus = n + nPlus; + n = nPlus - n; + } + + return [n, nPlus, n * nPlus === prod]; +} + +// console.log(fib(55), [21, 34, true]); +console.log(fib(714), [21, 34, true]); +// console.log(fib(800), [34, 55, false]); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 | + + + + + + + + + + + + + + + + + + + +1x +5x +5x +5x +5x +5x + +5x + +12x +8x +5x +8x +3x +3x +8x + + +12x +6x +6x +6x +6x + +12x +5x +5x + +7x +7x +7x + + +5x +1x + + | // You are given an array(which will have a length of at least 3, but could be very large) containing integers.
+// The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer
+// N.Write a method that takes the array as an argument and returns this "outlier" N.
+//
+//
+// [2, 4, 0, 100, 4, 11, 2602, 36] --> 11 (the only odd number)
+
+// [160, 3, 1719, 19, 11, 13, -21] --> 160 (the only even number)
+//
+//
+
+
+// export function findOUtlier(integers: number[]): number {
+
+// const isEvenNum = integers.filter(num => num % 2 == 0);
+// const isOddNum = integers.filter(num => num % 2 != 0);
+
+// return isEvenNum.length == 1 ? Number(isEvenNum) : Number(isOddNum);
+// };
+
+export function findOUtlier(integers: number[]): number {
+ const evenNum: number[] = [];
+ const oddNum: number[] = [];
+ const middle = Math.trunc(integers.length / 2);
+ let end = integers.length - 1;
+ let start = 0;
+
+ while (start < middle || end >= middle) {
+
+ if (start !== middle) {
+ if (!(integers[start] % 2)) {
+ evenNum.push(integers[start])
+ } else {
+ oddNum.push(integers[start])
+ }
+ }
+
+
+ if (!(integers[end] % 2)) {
+ evenNum.push(integers[end])
+ } else {
+ oddNum.push(integers[end])
+ }
+
+ if (evenNum.length === 1 && oddNum.length > 1 || oddNum.length === 1 && evenNum.length > 1) {
+ break;
+ }
+
+ start++;
+ end--;
+ }
+
+
+ return evenNum.length === 1 ? evenNum[0] : oddNum[0];
+};
+
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| findOUtlier.ts | +
+
+ |
+ 100% | +27/27 | +100% | +14/14 | +100% | +1/1 | +100% | +27/27 | +
| index.ts | +
+
+ |
+ 0% | +0/2 | +0% | +0/1 | +0% | +0/1 | +0% | +0/2 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 | + + + | import { findOUtlier } from "./findOUtlier"; + +export default findOUtlier; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| cheinAddFun.ts | +
+
+ |
+ 0% | +0/8 | +100% | +1/1 | +100% | +1/1 | +0% | +0/8 | +
| duplicateEncodedr.ts | +
+
+ |
+ 0% | +0/37 | +0% | +0/1 | +0% | +0/1 | +0% | +0/37 | +
| endingStrings.ts | +
+
+ |
+ 0% | +0/12 | +0% | +0/1 | +0% | +0/1 | +0% | +0/12 | +
| factorial.js | +
+
+ |
+ 0% | +0/20 | +0% | +0/1 | +0% | +0/1 | +0% | +0/20 | +
| fib.ts | +
+
+ |
+ 0% | +0/10 | +100% | +1/1 | +100% | +1/1 | +0% | +0/10 | +
| insertionsort.ts | +
+
+ |
+ 0% | +0/42 | +0% | +0/1 | +0% | +0/1 | +0% | +0/42 | +
| isTriangle.ts | +
+
+ |
+ 0% | +0/12 | +0% | +0/1 | +0% | +0/1 | +0% | +0/12 | +
| main.ts | +
+
+ |
+ 0% | +0/9 | +0% | +0/1 | +0% | +0/1 | +0% | +0/9 | +
| maxLengthSubString.ts | +
+
+ |
+ 0% | +0/27 | +0% | +0/1 | +0% | +0/1 | +0% | +0/27 | +
| minMaxNumber.ts | +
+
+ |
+ 0% | +0/28 | +0% | +0/1 | +0% | +0/1 | +0% | +0/28 | +
| nbYear.ts | +
+
+ |
+ 0% | +0/14 | +0% | +0/1 | +0% | +0/1 | +0% | +0/14 | +
| paperwork.ts | +
+
+ |
+ 0% | +0/5 | +0% | +0/1 | +0% | +0/1 | +0% | +0/5 | +
| sumArray.ts | +
+
+ |
+ 0% | +0/12 | +0% | +0/1 | +0% | +0/1 | +0% | +0/12 | +
| task.js | +
+
+ |
+ 0% | +0/9 | +0% | +0/1 | +0% | +0/1 | +0% | +0/9 | +
| towerBuilder.ts | +
+
+ |
+ 0% | +0/12 | +0% | +0/1 | +0% | +0/1 | +0% | +0/12 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | const STR = "insertionsort"; +const SORT_STR = "eiinnoorrsstt"; +const NUMB = [12, -2, 55, 68, 80]; +const SORT_NUMB = [-2, 12, 55, 68, 80]; + +const WORDS = ["strc", "avgrs", "bds"]; +const SORT_WORDS = ["avgrs", "bds", "strc"]; + +function swapCharsInString(str: string, i: number, j: number) { + return ( + str.substring(0, i) + + str[j] + + str.substring(i + 1, j) + + str[i] + + str.substring(j + 1) + ); +} + +const swapElements = ( + arr: number[] | string[], + index1: number, + index2: number, +) => { + [arr[index1], arr[index2]] = [arr[index2], arr[index1]]; +}; + +export function insertionSort(str: string): string; +export function insertionSort(arr: number[]): number[]; +export function insertionSort(arr: string[]): string[]; + +export function insertionSort(sortItems: string | number[] | string[]) { + let L: number, R: number; + + for (L = 1; L < sortItems.length; L++) { + R = L; + + while (R > 0 && sortItems[R] < sortItems[R - 1]) { + const index1 = R; + const index2 = R - 1; + + if (typeof sortItems === "string") { + sortItems = swapCharsInString(sortItems, index2, index1); + } + + if (Array.isArray(sortItems)) { + swapElements(sortItems, index1, index2); + } + + R = R - 1; + } + } + + return sortItems; +} + +console.log(insertionSort(STR), SORT_STR); +console.log(insertionSort(NUMB), SORT_NUMB); +console.log(insertionSort(WORDS), SORT_WORDS); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| index.ts | +
+
+ |
+ 0% | +0/2 | +0% | +0/1 | +0% | +0/1 | +0% | +0/2 | +
| isDevided11.ts | +
+
+ |
+ 79.31% | +23/29 | +66.66% | +4/6 | +100% | +1/1 | +79.31% | +23/29 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 | + + + | import { isDevided11 } from "./isDevided11"; + +export default isDevided11; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 | 1x +2x +2x +2x +2x + +2x +8x +8x + +8x +8x + +8x + + + + +8x +2x +2x +2x + +8x + + + + +8x +8x + +8x +8x + +8x + + +2x +1x + | export function isDevided11(numbers: number[]): number[] {
+ const res: number[] = [];
+ let L = 1;
+ let R = numbers.length - 1
+ let M = 0;
+
+ while (L <= numbers.length - 1 || R >= 0) {
+ const L_NUM = numbers[L];
+ const R_NUM = numbers[R];
+
+ while (M <= numbers.length - 1) {
+ const M_NUM = numbers[M];
+
+ if (((L_NUM + R_NUM) - M_NUM) % 11 === 0) {
+ res.push(+`${L_NUM}${M_NUM}${R_NUM}`)
+ res.push(+`${R_NUM}${M_NUM}${L_NUM}`)
+ }
+
+ if (((L_NUM + M_NUM) - R_NUM) % 11 === 0) {
+ res.push(+`${L_NUM}${R_NUM}${M_NUM}`)
+ res.push(+`${M_NUM}${R_NUM}${L_NUM}`)
+ }
+
+ if (((R_NUM + M_NUM) - L_NUM) % 11 === 0) {
+ res.push(+`${R_NUM}${L_NUM}${M_NUM}`)
+ res.push(+`${M_NUM}${L_NUM}${R_NUM}`)
+ }
+
+ M++
+ }
+
+ L++
+ R--
+
+ }
+
+
+ return res;
+};
+ |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 | + + + + + + + + + + + + + + | export function isTriangle(a: number, b: number, c: number): boolean { + if (a < 0 || b < 0 || c < 0) return false; + + return a + b > c && a < b + c && b < a + c; +} + +console.log(isTriangle(7, 2, 2), false); +console.log(isTriangle(1, 2, 2), true); +console.log(isTriangle(4, 2, 3), true); +console.log(isTriangle(2, 2, 2), true); +console.log(isTriangle(1, 2, 3), false); +console.log(isTriangle(-5, 1, 3), false); +console.log(isTriangle(0, 2, 3), false); +console.log(isTriangle(1, 2, 9), false); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 | + + + + + + + + + | export function setupCounter(element: HTMLButtonElement) { + let counter = 0 + const setCounter = (count: number) => { + counter = count + element.innerHTML = `count is ${counter}` + } + element.addEventListener('click', () => setCounter(++counter)) + setCounter(0) +} + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | export function maxLengthSubString(str: string): number { + const endIndex = str.length - 1; + let res = 1; + let L = 0; + let R = 1; + let subStr = str[L]; + + if (!str) return 0; + if (str.length < 2) return 1; + + while (L <= endIndex && R <= endIndex) { + if (!subStr.includes(str[R])) { + subStr = subStr + str[R]; + res = Math.max(subStr.length, res); + R++; + } else { + L++; + subStr = str[L]; + R = L + 1; + } + } + + return res; +} + +console.log(maxLengthSubString("a"), "expect: " + 1); +console.log(maxLengthSubString(""), "expect: " + 0); + +console.log(maxLengthSubString("abcabcbb"), "expect: " + 3); +console.log(maxLengthSubString("ab"), "expect: " + 2); +console.log(maxLengthSubString("aaaaaa"), "expect: " + 1); +console.log(maxLengthSubString("aabcDfffaaaa"), "expect: " + 5); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | export const min = (list: number[]): number => { + list.sort(); + let L = 0; + let R = list.length - 1; + let res = list[L]; + + while (L <= R) { + res = Math.min(list[L], list[R], res); + + L++; + R--; + } + + return res; +}; + +export const max = (list: number[]): number => { + list.sort(); + let L = 0; + let R = list.length - 1; + let res = list[L]; + + while (L <= R) { + res = Math.max(list[L], list[R], res); + + L++; + R--; + } + + return res; +}; + +// const min = (list) => Math.min(...list); +// const max = (list) => Math.max(...list); + +// export const min = (list: number[]): number => { +// return list.sort((leftvalue, rightvalue): number => { +// return leftvalue - rightvalue; +// })[0]; +// }; + +// export const max = (list: number[]): number => { +// return list.sort((leftvalue, rightvalue): number => { +// return leftvalue - rightvalue; +// })[list.length - 1]; +// }; + +console.log(min([-52, 56, 30, 29, -54, 0, -110]), -110); +console.log(min([42, 54, 65, 87, 0]), 0); + +console.log(max([4, 6, 2, 1, 9, 63, -134, 566]), 566); +console.log(max([5]), 5); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 | + + + + + + + + + + + + + + + + + + | export const nbYear = (p0: number, percent: number, aug: number, p: number): number => { + + let year = 0 + + while (p0 < p) { + p0 += Math.floor(p0 * percent / 100) + aug + year++ + } + + return year +} + +console.log( + nbYear(1500, 5, 100, 5000), 15 +) +console.log( + nbYear(1500000, 2.5, 10000, 2000000), 10 +) + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 | + + + + + + | export function paperwork(n: number, m: number): number { + if (n < 0 || m < 0) return 0; + return n * m; +} + +console.log(paperwork(45, 29)) + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 | + + + + + + + + + + + + + | export function sumArray(array: number[] | null): number { + if (Array.isArray(array) && array.length > 0) { + array.sort((a, b) => a - b); + array.shift(); + array.pop(); + return array.reduce((acc, currentValue) => acc + currentValue, 0) + } + return 0; +} + +console.log(sumArray([6, 2, 1, 8, 10]), 16); +console.log(sumArray([6, 0, 1, 10, 10]), 17) +console.log('slice(1, -1): [ 6, 0, 1, 10, 10 ]', [6, 0, 1, 10, 10].slice(1, -1)) + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 | + + + + + + + + + | function getReversedNumber(num) { + const isNegative = num < 0; + const reverseNumber = parseInt([...("" + Math.abs(num))].reverse().join("")); + + return isNegative ? reverseNumber * -1 : reverseNumber; +} + +console.log(getReversedNumber(12)); +console.log(getReversedNumber(-123)); + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 | + + + + + + + + + + + + + + + + + | export const towerBuilder = (nFloors: number): string[] => { + + const floors: string[] = []; + + for (let n = 1; n < nFloors + 1; n++) { + const stars = "*".repeat(n * 2 - 1); + const space = ' '.repeat(nFloors - n); + const res = space + stars + space; + floors.push(res); + } + + return floors; + +} + +console.log(towerBuilder(3)) +console.log(towerBuilder(6)) + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| main.ts | +
+
+ |
+ 0% | +0/6 | +0% | +0/1 | +0% | +0/1 | +0% | +0/6 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| 1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 | + + + + + + + + + + + + + + + + + + + + + + + | import './style.css' +import typescriptLogo from './typescript.svg' +import { setupCounter } from '../lib/main' + +document.querySelector<HTMLDivElement>('#app')!.innerHTML = ` + <div> + <a href="https://vitejs.dev" target="_blank"> + <img src="/vite.svg" class="logo" alt="Vite logo" /> + </a> + <a href="https://www.typescriptlang.org/" target="_blank"> + <img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" /> + </a> + <h1>Vite + TypeScript</h1> + <div class="card"> + <button id="counter" type="button"></button> + </div> + <p class="read-the-docs"> + Click on the Vite and TypeScript logos to learn more + </p> + </div> +` + +setupCounter(document.querySelector<HTMLButtonElement>('#counter')!) + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +| File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
|---|---|---|---|---|---|---|---|---|---|
| algorithms | +
+
+ |
+ 0% | +0/55 | +0% | +0/1 | +0% | +0/1 | +0% | +0/55 | +
| algorithms/lib | +
+
+ |
+ 0% | +0/257 | +13.33% | +2/15 | +13.33% | +2/15 | +0% | +0/257 | +
| algorithms/lib/binarySearch | +
+
+ |
+ 94.44% | +17/18 | +85.71% | +6/7 | +50% | +1/2 | +94.44% | +17/18 | +
| algorithms/lib/findOUtlier | +
+
+ |
+ 93.1% | +27/29 | +93.33% | +14/15 | +50% | +1/2 | +93.1% | +27/29 | +
| algorithms/lib/isDevided11 | +
+
+ |
+ 74.19% | +23/31 | +57.14% | +4/7 | +50% | +1/2 | +74.19% | +23/31 | +
| algorithms/src | +
+
+ |
+ 0% | +0/6 | +0% | +0/1 | +0% | +0/1 | +0% | +0/6 | +