Skip to content
Open
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
16 changes: 15 additions & 1 deletion task-1/count-above-threshold.js
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
//Your code here
function countAboveThreshold(numbers, threshold) {
if (numbers.length === 0) {
return 0;
}
let counter = 0;
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] > threshold) {
counter++;
}
}
return counter;
}
console.log(countAboveThreshold([1,5,10,3],4))// returns 2
console.log(countAboveThreshold([7,8,9],10))// returns 0
console.log(countAboveThreshold([],5))// returns 0
22 changes: 22 additions & 0 deletions task-2/calculateAverage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, expect } from "vitest";
import { calculateAverage } from "./calculateAverage.js";

test("calculateAverage function with array [2, 4, 6] should return 4", () => {
expect(calculateAverage([2, 4, 6])).toBe(4);
});

test("array with a single number 5 should return 5", () => {
expect(calculateAverage([5])).toBe(5);
});

test("empty array [] should return null", () => {
expect(calculateAverage([])).toBe(null);
});

test("non-array input '123' should return null", () => {
expect(calculateAverage(['123'])).toBe(null);
});

test("An array containing a non-number value [1, 2, '3'] should return null", () => {
expect(calculateAverage([1, 2, '3'])).toBe(null);
});
Loading