From 1b6cc9b1f4c6bf23abe8aa1d9307f6de9e697a2f Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Fri, 13 Mar 2026 21:34:50 +0000 Subject: [PATCH] Refactor includes implementation to use for...of loop --- Sprint-1/refactor/includes.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..145603948 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,12 +1,15 @@ // Refactor the implementation of includes to use a for...of loop function includes(list, target) { - for (let index = 0; index < list.length; index++) { - const element = list[index]; + // Loop through each element in the list using a for...of loop + for (const element of list) { + // If the current element matches the target, return true if (element === target) { return true; } } + + // If the loop finishes without finding the target, return false return false; }