diff --git a/lesson_07/conditionals/.env.test b/lesson_07/conditionals/.env.test index de8c44249..6823e4a7d 100644 --- a/lesson_07/conditionals/.env.test +++ b/lesson_07/conditionals/.env.test @@ -1 +1 @@ -HW_VERSION=your homework version here \ No newline at end of file +HW_VERSION=C \ No newline at end of file diff --git a/lesson_07/conditionals/package-lock.json b/lesson_07/conditionals/package-lock.json index 15945122d..465b72937 100644 --- a/lesson_07/conditionals/package-lock.json +++ b/lesson_07/conditionals/package-lock.json @@ -22,7 +22,7 @@ "eslint-config-prettier": "^9.1.0", "jest": "^29.7.0", "prettier": "3.4.2", - "ts-jest": "^29.2.5", + "ts-jest": "^29.2.6", "ts-node": "^10.9.2", "typescript": "^5.7.2", "typescript-eslint": "^8.18.0" @@ -5340,9 +5340,9 @@ } }, "node_modules/ts-jest": { - "version": "29.2.5", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.2.5.tgz", - "integrity": "sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==", + "version": "29.2.6", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.2.6.tgz", + "integrity": "sha512-yTNZVZqc8lSixm+QGVFcPe6+yj7+TWZwIesuOWvfcn4B9bz5x4NDzVCQQjOs7Hfouu36aEqfEbo9Qpo+gq8dDg==", "dev": true, "license": "MIT", "dependencies": { @@ -5353,7 +5353,7 @@ "json5": "^2.2.3", "lodash.memoize": "^4.1.2", "make-error": "^1.3.6", - "semver": "^7.6.3", + "semver": "^7.7.1", "yargs-parser": "^21.1.1" }, "bin": { @@ -5389,9 +5389,9 @@ } }, "node_modules/ts-jest/node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", + "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, "license": "ISC", "bin": { diff --git a/lesson_07/conditionals/package.json b/lesson_07/conditionals/package.json index f5f8dd4fd..ef6c23b80 100644 --- a/lesson_07/conditionals/package.json +++ b/lesson_07/conditionals/package.json @@ -26,7 +26,7 @@ "eslint-config-prettier": "^9.1.0", "jest": "^29.7.0", "prettier": "3.4.2", - "ts-jest": "^29.2.5", + "ts-jest": "^29.2.6", "ts-node": "^10.9.2", "typescript": "^5.7.2", "typescript-eslint": "^8.18.0" diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index cc44be44c..0794ed1f6 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -1,3 +1,4 @@ +import { log } from "console"; import { computeLexicographicDistance } from "./util.js"; /** @@ -13,10 +14,17 @@ export function compareStrings(a: string, b: string): number { const distance = computeLexicographicDistance(a, b); // TODO(you): Finish this method. - - return 0; + if (distance < 0) { + return -1; + } else if (distance > 0) { + return 1; + } + else { + return 0; + } } + /** * Computes the factorial of the given value of `n`. * @@ -24,9 +32,16 @@ export function compareStrings(a: string, b: string): number { * @return The factorial of n. */ export function computeFactorial(n: number): number { - return 0; + if (n < 0) { + return 0; + } + if (n === 0) { + return 1; + } + return n * computeFactorial(n - 1); } + /** * Returns an array of the first `n` Fibonacci numbers starting from 1. * @@ -34,7 +49,13 @@ export function computeFactorial(n: number): number { * @return An array containing the first `n` Fibonacci values. */ export function getFirstNFibonacciNumbers(n: number): number[] { - return []; + if(n <= 0) return []; + if(n === 1) return[1]; + const fib: number[] = [1,1]; +for(let i = 2; i < n; i++){ + fib.push(fib[i - 1] + fib[i - 2]); +} +return fib; } /** @@ -58,12 +79,22 @@ export function binarySearch( } const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. - + const pivotValue = values[pivotIndex]; + if (pivotValue === value) { + return pivotIndex; + } + if (pivotValue > value) { + return binarySearch(values, start, pivotIndex - 1, value); + } + if (pivotValue < value){ + return binarySearch(values, pivotIndex + 1, end, value); +} +return -1; +} // TODO(you): Finish implementing this algorithm // If values[pivotIndex] is equal to value then return `pivotIndex`. // Else if values[pivotIndex] is greater than the value, then // call `binarySearch(values, start, pivotIndex - 1, value)` and return its value; // Else call `binarySearch(values, pivotIndex + 1, end, value)` and return its value. - return -1; -} + \ No newline at end of file diff --git a/lesson_07/conditionals/src/part_c.ts b/lesson_07/conditionals/src/part_c.ts index 6effb3b47..ef5fa7171 100644 --- a/lesson_07/conditionals/src/part_c.ts +++ b/lesson_07/conditionals/src/part_c.ts @@ -6,8 +6,15 @@ * @returns */ export function isStrongPassword(password: string): boolean { - return false; + + if (password.length < 8){ + return false; } + const passUpperCase = /[A-Z]/.test(password); + const passNumber=/\d/.test(password); + return passUpperCase && passNumber; + } + /** * Determines the day of the week on the given 0-based number. @@ -16,8 +23,24 @@ export function isStrongPassword(password: string): boolean { * @returns */ export function getDayOfWeek(day: number): string { + if(day==0){ + return "Sunday"; + } else if(day==1){ + return "Monday"; + } else if(day==2){ + return "Tuesday"; + } else if(day==3){ + return "Wednesday" + } else if(day==4){ + return "Thursday"; + }else if(day==5){ + return "Friday"; + } else if(day==6){ + return "Saturday"; + }else{ return ""; } +} /** * Determines the ticket price based on the given age. The price is @@ -31,5 +54,15 @@ export function getDayOfWeek(day: number): string { * @returns */ export function getTicketPrice(age: number): number { - return 0; + if(age <= 5){ + return 0; + }else if(age >= 5 && age <= 17){ + return 10; + }else if(age >= 18 && age <= 59){ + return 20; + }else{ + return 15; + } } + +