From eb310876ae4f759c352b4a886d81ed5a88b7cc11 Mon Sep 17 00:00:00 2001 From: Mustafa Homsi Date: Wed, 11 Feb 2026 09:39:31 +0100 Subject: [PATCH 1/4] t1w5 done --- task-1/count-above-threshold.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/task-1/count-above-threshold.js b/task-1/count-above-threshold.js index 7cf0418..35d081f 100644 --- a/task-1/count-above-threshold.js +++ b/task-1/count-above-threshold.js @@ -1 +1,12 @@ -//Your code here +function countAboveThreshold(numbers, threshold) { + let count = 0; + + for (let i = 0; i < numbers.length; i++) { + if (numbers[i] > threshold) { + count++; + } + } + + return count; +} +module.exports = countAboveThreshold; From fba2b304226178c04dc4e7eb366f49b2f5723ff0 Mon Sep 17 00:00:00 2001 From: Mustafa Homsi Date: Wed, 11 Feb 2026 10:27:19 +0100 Subject: [PATCH 2/4] mustafa homsi --- task-2/calculateAverage.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 task-2/calculateAverage.test.js diff --git a/task-2/calculateAverage.test.js b/task-2/calculateAverage.test.js new file mode 100644 index 0000000..a5a1dc9 --- /dev/null +++ b/task-2/calculateAverage.test.js @@ -0,0 +1,28 @@ +import { describe, it, expect } from "vitest"; +import { calculateAverage } from "./calculateAverage"; + +describe("calculateAverage", () => { + it("returns average for valid numbers", () => { + expect(calculateAverage([2, 4, 6])).toBe(4); + }); + + it("returns number for single value", () => { + expect(calculateAverage([5])).toBe(5); + }); + + it("returns null for empty array", () => { + expect(calculateAverage([])).toBe(null); + }); + + it("returns null if input is not array", () => { + expect(calculateAverage("123")).toBe(null); + }); + + it("returns null if array contains non-number", () => { + expect(calculateAverage([1, 2, "3"])).toBe(null); + }); + + it("works with decimal numbers", () => { + expect(calculateAverage([1.5, 2.5])).toBe(2); + }); +}); \ No newline at end of file From 2aed06254c8b695ae7c110c4ca062015d59e8852 Mon Sep 17 00:00:00 2001 From: homsi6313-art Date: Wed, 11 Feb 2026 10:56:32 +0100 Subject: [PATCH 3/4] Fix vowel counting logic in countVowels function --- task-3/count-vowels-debug.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/task-3/count-vowels-debug.js b/task-3/count-vowels-debug.js index 1ce292b..4c9c109 100644 --- a/task-3/count-vowels-debug.js +++ b/task-3/count-vowels-debug.js @@ -1,13 +1,15 @@ function countVowels(text) { let count = 0; - for (let i = 0; i <= text.length; i++) { + for (let i = 0; i < text.length; i++) { + const char = text[i].toLowerCase(); + if ( - text[i] === "a" || - text[i] === "e" || - text[i] === "i" || - text[i] === "o" || - text[i] === "u" + char === "a" || + char === "e" || + char === "i" || + char === "o" || + char === "u" ) { count++; } @@ -15,3 +17,7 @@ function countVowels(text) { return count; } +countVowels("hello") // 2 +countVowels("javascript") // 3 +countVowels("") // 0 +countVowels("HELLO") // 2 From 785d0648973f843f2641eca7552ee8e7f2c2ca54 Mon Sep 17 00:00:00 2001 From: homsi6313-art Date: Wed, 11 Feb 2026 13:06:08 +0100 Subject: [PATCH 4/4] Add linear and binary search implementations Implemented linear and binary search functions with performance tests on arrays of different sizes. --- task-4/search-experiment.js | 79 +++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/task-4/search-experiment.js b/task-4/search-experiment.js index 63c189a..12c29ce 100644 --- a/task-4/search-experiment.js +++ b/task-4/search-experiment.js @@ -1,3 +1,76 @@ -// Write your code here -// Use generateBigArray to create a big array numbers. -// Example: generateBigArray(1000000) will create an array of 1 million numbers. \ No newline at end of file +import generateBigArray from "./bigArray.js"; + +// Linear Search +// ------------------------- +function linearSearch(array, target) { + for (let i = 0; i < array.length; i++) { + if (array[i] === target) { + return i; + } + } + return -1; +} +// Binary Search +// ------------------------- +function binarySearch(array, target) { + let left = 0; + let right = array.length - 1; + + while (left <= right) { + const mid = Math.floor((left + right) / 2); + + if (array[mid] === target) { + return mid; + } + + if (array[mid] < target) { + left = mid + 1; + } else { + right = mid - 1; + } + } + + return -1; +} + +// Generate Arrays (NOT timed) +// ------------------------- +const array1K = generateBigArray(1000); +const array100K = generateBigArray(100000); +const array10M = generateBigArray(10000000); + +const target = 123456789; // A number that is not in the arrays to test worst-case scenario + +// Linear Search Tests +// ------------------------- +console.time("Linear Search 1K"); +linearSearch(array1K, target); +console.timeEnd("Linear Search 1K"); + +console.time("Linear Search 100K"); +linearSearch(array100K, target); +console.timeEnd("Linear Search 100K"); + +console.time("Linear Search 10M"); +linearSearch(array10M, target); +console.timeEnd("Linear Search 10M"); + +console.log("----------------------------"); + +// Binary Search Tests +// ------------------------- +console.time("Binary Search 1K"); +binarySearch(array1K, target); +console.timeEnd("Binary Search 1K"); + +console.time("Binary Search 100K"); +binarySearch(array100K, target); +console.timeEnd("Binary Search 100K"); + +console.time("Binary Search 10M"); +binarySearch(array10M, target); +console.timeEnd("Binary Search 10M"); +// Reflection: +// Binary Search was much faster than Linear Search, +// especially for large arrays because it has O(log n) +// complexity compared to O(n).