Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions lesson_07/conditionals/src/part_f.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as jest from "@jest/globals";
import { countCharacter, getLetterGrade, sumEvenNumbers } from "./part_f.js";

const describe =
!process.env.HW_VERSION || process.env.HW_VERSION === "F"
? jest.describe
: jest.describe.skip;

describe("getLetterGrade", () => {
it("should return 'A' for scores 90-100", () => {
expect(getLetterGrade(95)).toBe("A");
expect(getLetterGrade(90)).toBe("A");
expect(getLetterGrade(100)).toBe("A");
});

it("should return 'B' for scores 80-89", () => {
expect(getLetterGrade(85)).toBe("B");
expect(getLetterGrade(80)).toBe("B");
expect(getLetterGrade(89)).toBe("B");
});

it("should return 'C' for scores 70-79", () => {
expect(getLetterGrade(75)).toBe("C");
expect(getLetterGrade(70)).toBe("C");
expect(getLetterGrade(79)).toBe("C");
});

it("should return 'D' for scores 60-69", () => {
expect(getLetterGrade(65)).toBe("D");
expect(getLetterGrade(60)).toBe("D");
expect(getLetterGrade(69)).toBe("D");
});

it("should return 'F' for scores below 60", () => {
expect(getLetterGrade(59)).toBe("F");
expect(getLetterGrade(0)).toBe("F");
expect(getLetterGrade(45)).toBe("F");
});
});

describe("sumEvenNumbers", () => {
it("should return 0 for an empty array", () => {
expect(sumEvenNumbers([])).toBe(0);
});

it("should return the sum of even numbers", () => {
expect(sumEvenNumbers([1, 2, 3, 4, 5, 6])).toBe(12); // 2 + 4 + 6
expect(sumEvenNumbers([2, 4, 6, 8])).toBe(20);
});

it("should return 0 if no even numbers exist", () => {
expect(sumEvenNumbers([1, 3, 5, 7])).toBe(0);
});

it("should handle negative even numbers", () => {
expect(sumEvenNumbers([-2, -1, 0, 1, 2])).toBe(0); // -2 + 0 + 2
});
});

describe("countCharacter", () => {
it("should count occurrences of a character", () => {
expect(countCharacter("hello", "l")).toBe(2);
expect(countCharacter("hello", "o")).toBe(1);
expect(countCharacter("hello", "h")).toBe(1);
});

it("should return 0 if character is not found", () => {
expect(countCharacter("hello", "x")).toBe(0);
});

it("should handle empty string", () => {
expect(countCharacter("", "a")).toBe(0);
});

it("should be case sensitive", () => {
expect(countCharacter("Hello", "h")).toBe(0);
expect(countCharacter("Hello", "H")).toBe(1);
});
});
31 changes: 31 additions & 0 deletions lesson_07/conditionals/src/part_f.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Determines the grade letter based on a numeric score.
* A: 90-100, B: 80-89, C: 70-79, D: 60-69, F: below 60
*
* @param score
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param score - The numeric score to convert to a letter grade'.

Suggested change
* @returns
* @param {number} score - The numeric score to convert to a letter grade.
* @returns {string} The letter grade corresponding to the score.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns The letter grade (A, B, C, D, or F) corresponding to the score'.

Suggested change
* @returns
* @param score The numeric score to convert to a letter grade.
* @returns The letter grade (A, B, C, D, or F) corresponding to the score.

Copilot uses AI. Check for mistakes.
*/
export function getLetterGrade(score: number): string {
return "";
}

/**
* Calculates the sum of all even numbers in the given array.
*
* @param numbers
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param numbers - Array of numbers to sum even values from'.

Suggested change
* @returns
* @param numbers - number[] - Array of numbers to sum even values from.
* @returns number - The sum of all even numbers in the array.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns The sum of all even numbers in the array'.

Suggested change
* @returns
* @param numbers The array of numbers to process.
* @returns The sum of all even numbers in the array.

Copilot uses AI. Check for mistakes.
*/
export function sumEvenNumbers(numbers: number[]): number {
return 0;
}

/**
* Counts how many times a specific character appears in a string.
*
* @param text
* @param character
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param text - The string to search in'.

Suggested change
* @returns
* @param {string} text - The string to search in.
* @param {string} character - The character to count occurrences of.
* @returns {number} The number of times the character appears in the string.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param character - The character to count occurrences of'.

Suggested change
* @returns
* @param text {string} - The string to search within.
* @param character {string} - The character to count occurrences of.
* @returns {number} The number of times the character appears in the string.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns The number of times the character appears in the text'.

Suggested change
* @returns
* @param text The string to search.
* @param character The character to count.
* @returns The number of times the character appears in the text.

Copilot uses AI. Check for mistakes.
*/
export function countCharacter(text: string, character: string): number {
return 0;
}
72 changes: 72 additions & 0 deletions lesson_07/conditionals/src/part_g.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as jest from "@jest/globals";
import { daysUntilBirthday, findLargestNumber, isPalindrome } from "./part_g.js";

const describe =
!process.env.HW_VERSION || process.env.HW_VERSION === "G"
? jest.describe
: jest.describe.skip;

describe("findLargestNumber", () => {
it("should find the largest number in an array", () => {
expect(findLargestNumber([1, 5, 3, 9, 2])).toBe(9);
expect(findLargestNumber([10, 20, 5, 30])).toBe(30);
});

it("should handle arrays with one element", () => {
expect(findLargestNumber([42])).toBe(42);
});

it("should handle negative numbers", () => {
expect(findLargestNumber([-1, -5, -3])).toBe(-1);
});

it("should handle arrays with duplicate largest values", () => {
expect(findLargestNumber([5, 5, 5])).toBe(5);
});
});

describe("isPalindrome", () => {
it("should return true for palindromes", () => {
expect(isPalindrome("racecar")).toBe(true);
expect(isPalindrome("A man a plan a canal Panama")).toBe(true);
expect(isPalindrome("race a car")).toBe(false);
});

it("should ignore case", () => {
expect(isPalindrome("Racecar")).toBe(true);
expect(isPalindrome("RaceCar")).toBe(true);
});

it("should ignore spaces", () => {
expect(isPalindrome("race car")).toBe(false);
expect(isPalindrome("taco cat")).toBe(true);
});

it("should handle empty string", () => {
expect(isPalindrome("")).toBe(true);
});

it("should handle single character", () => {
expect(isPalindrome("a")).toBe(true);
});
});

describe("daysUntilBirthday", () => {
it("should calculate days until birthday in same year", () => {
// Birthday is later in the same year
expect(daysUntilBirthday(3, 15, 6, 15)).toBe(92); // March 15 to June 15 (roughly)
});

it("should calculate days until birthday next year", () => {
// Birthday already passed this year
expect(daysUntilBirthday(6, 15, 3, 15)).toBe(273); // June 15 to March 15 next year (roughly)
});

it("should return 0 if today is the birthday", () => {
expect(daysUntilBirthday(5, 20, 5, 20)).toBe(0);
});

it("should handle birthdays tomorrow", () => {
expect(daysUntilBirthday(5, 20, 5, 21)).toBe(1);
});
});
40 changes: 40 additions & 0 deletions lesson_07/conditionals/src/part_g.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Finds the largest number in an array.
*
* @param numbers
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param numbers - Array of numbers to find the largest from'.

Suggested change
* @returns
* @param numbers {number[]} Array of numbers to find the largest from.
* @returns {number} The largest number in the array.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns The largest number in the array'.

Suggested change
* @returns
* @param numbers The array of numbers to search.
* @returns The largest number in the array.

Copilot uses AI. Check for mistakes.
*/
export function findLargestNumber(numbers: number[]): number {
return 0;
}

/**
* Determines if a string is a palindrome (reads the same forwards and backwards).
* Ignore case and spaces.
*
* @param text
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param text - The string to check for palindrome'.

Suggested change
* @param text
* @param text - The string to check for palindrome

Copilot uses AI. Check for mistakes.
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns True if the text is a palindrome, false otherwise'.

Suggested change
* @returns
* @returns True if the text is a palindrome (ignoring case and spaces), false otherwise.

Copilot uses AI. Check for mistakes.
*/
export function isPalindrome(text: string): boolean {
return false;
}

/**
* Calculates the number of days until the next birthday.
* Assume currentMonth and currentDay represent today's date,
* and birthMonth and birthDay represent the birthday.
*
* @param currentMonth (1-12)
* @param currentDay (1-31)
* @param birthMonth (1-12)
* @param birthDay (1-31)
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns The number of days until the next birthday'.

Suggested change
* @returns
* @returns The number of days until the next birthday.

Copilot uses AI. Check for mistakes.
*/
export function daysUntilBirthday(
currentMonth: number,
currentDay: number,
birthMonth: number,
birthDay: number
): number {
return 0;
}
96 changes: 96 additions & 0 deletions lesson_07/conditionals/src/part_h.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as jest from "@jest/globals";
import { convertTemperature, findGCD, generateMultiplicationTable } from "./part_h.js";

const describe =
!process.env.HW_VERSION || process.env.HW_VERSION === "H"
? jest.describe
: jest.describe.skip;

describe("generateMultiplicationTable", () => {
it("should generate multiplication table for a given number", () => {
const result = generateMultiplicationTable(3);
expect(result).toEqual([
"3 x 1 = 3",
"3 x 2 = 6",
"3 x 3 = 9",
"3 x 4 = 12",
"3 x 5 = 15",
"3 x 6 = 18",
"3 x 7 = 21",
"3 x 8 = 24",
"3 x 9 = 27",
"3 x 10 = 30"
]);
});

it("should handle multiplication table for 1", () => {
const result = generateMultiplicationTable(1);
expect(result[0]).toBe("1 x 1 = 1");
expect(result[9]).toBe("1 x 10 = 10");
expect(result.length).toBe(10);
});
});

describe("findGCD", () => {
it("should find GCD of two positive numbers", () => {
expect(findGCD(12, 8)).toBe(4);
expect(findGCD(15, 25)).toBe(5);
expect(findGCD(17, 13)).toBe(1);
expect(findGCD(100, 75)).toBe(25);
});

it("should handle when one number is zero", () => {
expect(findGCD(5, 0)).toBe(5);
expect(findGCD(0, 7)).toBe(7);
});

it("should handle identical numbers", () => {
expect(findGCD(7, 7)).toBe(7);
expect(findGCD(20, 20)).toBe(20);
});

it("should handle when one number divides the other", () => {
expect(findGCD(20, 5)).toBe(5);
expect(findGCD(6, 18)).toBe(6);
});

it("should handle order independence", () => {
expect(findGCD(8, 12)).toBe(4);
expect(findGCD(12, 8)).toBe(4);
});
});

describe("convertTemperature", () => {
it("should convert Celsius to Fahrenheit", () => {
expect(convertTemperature(0, "C", "F")).toBe(32);
expect(convertTemperature(100, "C", "F")).toBe(212);
expect(convertTemperature(25, "C", "F")).toBe(77);
});

it("should convert Fahrenheit to Celsius", () => {
expect(convertTemperature(32, "F", "C")).toBe(0);
expect(convertTemperature(212, "F", "C")).toBe(100);
});

it("should convert Celsius to Kelvin", () => {
expect(convertTemperature(0, "C", "K")).toBe(273.15);
expect(convertTemperature(25, "C", "K")).toBe(298.15);
});

it("should convert Kelvin to Celsius", () => {
expect(convertTemperature(273.15, "K", "C")).toBe(0);
expect(convertTemperature(298.15, "K", "C")).toBe(25);
});

it("should return same temperature for same scales", () => {
expect(convertTemperature(25, "C", "C")).toBe(25);
expect(convertTemperature(77, "F", "F")).toBe(77);
});

it("should handle complex conversions", () => {
// F to K: (77°F - 32) × 5/9 + 273.15 = 298.15K
expect(convertTemperature(77, "F", "K")).toBeCloseTo(298.15, 2);
// K to F: (298.15K - 273.15) × 9/5 + 32 = 77°F
expect(convertTemperature(298.15, "K", "F")).toBeCloseTo(77, 2);
});
});
38 changes: 38 additions & 0 deletions lesson_07/conditionals/src/part_h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Generates a multiplication table for the given number up to 10.
* Returns an array of strings in the format "number x 1 = result".
*
* @param number
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param number - The number to generate multiplication table for'.

Suggested change
* @returns
* @param {number} number - The number to generate the multiplication table for.
* @returns {string[]} An array of strings representing the multiplication table.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns Array of strings representing the multiplication table'.

Suggested change
* @returns
* @param number The number for which to generate the multiplication table
* @returns Array of strings representing the multiplication table for the given number

Copilot uses AI. Check for mistakes.
*/
export function generateMultiplicationTable(number: number): string[] {
return [];
}

/**
* Finds the greatest common divisor (GCD) of two numbers using the Euclidean algorithm.
*
* @param a First number
* @param b Second number
* @returns The greatest common divisor of a and b
*/
export function findGCD(a: number, b: number): number {
return 0;
}

/**
* Converts a temperature from one scale to another.
* fromScale and toScale can be "C" (Celsius), "F" (Fahrenheit), or "K" (Kelvin).
*
* @param temperature
* @param fromScale
* @param toScale
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param temperature - The temperature value to convert'.

Suggested change
* @param toScale
* @param {number} temperature - The temperature value to convert.
* @param {string} fromScale - The scale to convert from ("C", "F", or "K").
* @param {string} toScale - The scale to convert to ("C", "F", or "K").

Copilot uses AI. Check for mistakes.
* @returns
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param fromScale - The source temperature scale (C, F, or K)'.

Suggested change
* @returns
* @param temperature {number} - The temperature value to convert.
* @param fromScale {string} - The source temperature scale ("C", "F", or "K").
* @param toScale {string} - The target temperature scale ("C", "F", or "K").
* @returns {number} - The converted temperature value.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @param documentation is incomplete. It should include the parameter type and description, e.g., '@param toScale - The target temperature scale (C, F, or K)'.

Suggested change
* @returns
* @param temperature {number} The temperature value to convert.
* @param fromScale {string} The scale to convert from ("C", "F", or "K").
* @param toScale {string} The scale to convert to ("C", "F", or "K").
* @returns {number} The converted temperature value.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @returns documentation is incomplete. It should describe what is returned, e.g., '@returns The converted temperature value'.

Suggested change
* @returns
* @returns The converted temperature value in the target scale.

Copilot uses AI. Check for mistakes.
*/
export function convertTemperature(
temperature: number,
fromScale: string,
toScale: string
): number {
return 0;
}
Loading