Skip to content

Commit b7c7831

Browse files
author
wakidurrahman
committed
feat: implement
1 parent 52b2f75 commit b7c7831

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/code-challenges/bubble-sort.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,25 @@ function luckySevensVariationOne(arrayOfIntegers) {
7575
}
7676

7777
luckySevensVariationOne([2, 1, 5, 1, 0]);
78+
79+
function luckySevensVariationTwo(array) {
80+
const len = array.length;
81+
82+
// Iterate through the array.
83+
84+
for (let i = 0; i < len - 2; i++) {
85+
let sum = array[i] + array[i + 1] + array[i + 2];
86+
87+
if (sum === 7) {
88+
return true; // Found three consecutive elements that sum to 3;
89+
}
90+
}
91+
92+
return false; // No three consecutive elements sum to 7;
93+
}
94+
95+
let numbersOfLuckySeven = [1, 2, 3, 4, 5, 6, 1];
96+
console.log(luckySevensVariationTwo(numbers)); // Output: true
97+
98+
var numbers2OfLuckySeven = [1, 2, 3, 4, 5, 6, 2];
99+
console.log(luckySevensVariationTwo(numbers2OfLuckySeven)); // Output: false

0 commit comments

Comments
 (0)