Skip to content

Commit 29686a8

Browse files
Merge pull request #93 from wakidurrahman/feat/code-challenges-005
feat: code
2 parents 99384b6 + 83e216f commit 29686a8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/code-challenges/code-challenges-003-010.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,26 @@ multiDimensionalSumOfSeveralArrayVariationReduce([[3, 2], [1], [4, 12]]);
4545

4646
/**
4747
* Q005: Test divisors of three
48+
* You will be given 2 parameters: a low and high number.
49+
* Your goal is to print all numbers between low and high, and for each of these numbers print whether or not the number is divisible by 3.
50+
* If the number is divisible by 3, print the word "div3" directly after the number.
4851
*/
52+
53+
function testDivisors(low, high) {
54+
// we'll store all numbers and strings within an array
55+
// instead of printing directly to the console.
56+
let output = [];
57+
58+
for (let i = low; i <= high; i++) {
59+
// simply store the current number in the output array
60+
output.push(i);
61+
62+
// Check if the current number is evenly divisible by 3
63+
if (i % 3 === 0) output.push('div3');
64+
}
65+
66+
// return all numbers and strings.
67+
return output;
68+
}
69+
70+
testDivisors(2, 10);

0 commit comments

Comments
 (0)