Loading workspace environment...
Understand algorithms: repeatable step-by-step procedures for solving problems.
function findLargestNumber(numbers) {
if (numbers.length === 0) return null;
let currentMax = numbers[0]; // Step 1: Assume first is largest
for (let i = 1; i < numbers.length; i++) {
if (numbers[i] > currentMax) {
currentMax = numbers[i]; // Found a new record!
}
}
return currentMax;
}
const testScores = [45, 89, 72, 98, 64, 91];
console.log("Highest score in class:", findLargestNumber(testScores));Highest score in class: 98let currentMax = numbers[0];Seeds initial maximum with first item.if (numbers[i] > currentMax)Compares each item to the current champion.let currentMax = 0; // If all numbers are negative [-10, -5, -20], this incorrectly outputs 0!let currentMax = numbers[0]; // Always seed with an actual element from the listArchitectural Explanation: Initializing to 0 fails if the dataset contains negative values.
findLargestNumber([5, 12, 3]);Write a function containsValue(list, target) that loops through list and returns true if target is found, otherwise false.