|
1 | | -import { computeLexicographicDistance } from "./util.js"; |
2 | | - |
3 | 1 | /** |
4 | | - * Compares two strings lexicographically. |
| 2 | + * Write a function that takes a single character as an argument and |
| 3 | + * returns boolean value true if the character is an uppercase letter. |
5 | 4 | * |
6 | | - * @param a The first `string` to compare. |
7 | | - * @param b The second `string` to compare. |
8 | | - * @return -1 if a is less than b, 1 if a is greater than b, and 0 otherwise. |
| 5 | + * @param char |
| 6 | + * @returns |
9 | 7 | */ |
10 | | -export function compareStrings(a: string, b: string): number { |
11 | | - // The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1 |
12 | | - // if it is greater, and 0 if the strings are equal. |
13 | | - const distance = computeLexicographicDistance(a, b); |
14 | | - |
15 | | - if (distance < 0) { |
16 | | - return -1; |
17 | | - } else if (distance > 0) { |
18 | | - return 1; |
19 | | - } else { |
20 | | - return 0; |
21 | | - } |
22 | | -} |
23 | | - /** |
24 | | - * Computes the factorial of the given value of `n`. |
25 | | - * |
26 | | - * @param n The value for which to compute the factorial. |
27 | | - * @return The factorial of n. |
28 | | - */ |
29 | | - export function computeFactorial(n: number): number { |
30 | | - if (n === 0 || n === 1) { |
31 | | - return 1; // Base case: 0! and 1! both equal 1 |
32 | | - } |
33 | | - return n * computeFactorial(n - 1); |
| 8 | +export function isUppercase(char: string): boolean { |
| 9 | + if (char >= "A" && char <= "Z") { |
| 10 | + return true; |
34 | 11 | } |
35 | 12 |
|
36 | | - /** |
37 | | - * Returns an array of the first `n` Fibonacci numbers starting from 1. |
38 | | - * |
39 | | - * @param n The first `n` of Fibonacci values to compute. |
40 | | - * @return An array containing the first `n` Fibonacci values. |
41 | | - */ |
42 | | - export function getFirstNFibonacciNumbers(n: number): number[] { |
43 | | - if (n <= 0) { |
44 | | - return []; |
45 | | - } |
46 | | - else if (n === 1) { |
47 | | - return [1]; |
48 | | - } |
49 | | - return []; |
50 | | - } |
51 | | - /** |
52 | | - * Finds a value in an array of values. |
53 | | - * |
54 | | - * @param values The values to search. |
55 | | - * @param start The left most index to search. |
56 | | - * @param end The right most index to search. |
57 | | - * @param value The value to look for. |
58 | | - * @return The index of the value if found in the array and -1 otherwise. |
59 | | - */ |
60 | | - export function binarySearch( |
61 | | - values: number[], |
62 | | - start: number, |
63 | | - end: number, |
64 | | - value: number, |
65 | | - ): number { |
66 | | - if (end < start) { |
67 | | - // The range is not valid so just return -1. |
68 | | - return -1; |
69 | | - } |
| 13 | + return false; |
| 14 | +} |
70 | 15 |
|
71 | | - const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. |
72 | | - if (values[pivotIndex] === value) { |
73 | | - return pivotIndex; |
74 | | - } else if (values[pivotIndex] > value) { |
75 | | - return binarySearch(values, start, pivotIndex - 1, value); |
76 | | - } else { |
77 | | - return binarySearch(values, pivotIndex + 1, end, value); |
78 | | - } |
| 16 | +/** |
| 17 | + * Determine if a person is eligible for a driving license (age and test passed). |
| 18 | + * |
| 19 | + * @param age |
| 20 | + * @param passedTest |
| 21 | + * @returns |
| 22 | + */ |
| 23 | +export function canGetDriverLicense(age: number, passedTest: boolean): boolean { |
| 24 | + if (age >= 18 && passedTest) { |
| 25 | + return true; |
| 26 | + } |
| 27 | + return false; |
| 28 | +} |
79 | 29 |
|
80 | | - // If values[pivotIndex] is equal to value then return `pivotIndex`. |
81 | | - // Else if values[pivotIndex] is greater than the value, then |
82 | | - // call `binarySearch(values, start, pivotIndex - 1, value)` and return its value; |
83 | | - // Else call `binarySearch(values, pivotIndex + 1, end, value)` and return its value. |
| 30 | +/** |
| 31 | + * Check if a store is open based on the day and time. The store is open |
| 32 | + * Monday to Saturday from 9 AM to 9 PM. |
| 33 | + * |
| 34 | + * @param day |
| 35 | + * @param hour |
| 36 | + * @returns |
| 37 | + */ |
| 38 | +export function isStoreOpen(day: string, hour: number): boolean { |
| 39 | + if (day === "Sunday" || hour < 9 || hour >= 21) { |
| 40 | + return false; |
| 41 | + } else { |
| 42 | + return true; |
84 | 43 | } |
| 44 | +} |
0 commit comments