Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48e5ab0

Browse files
committed
finished
1 parent 15a75a6 commit 48e5ab0

File tree

10 files changed

+70
-27
lines changed

10 files changed

+70
-27
lines changed

Week3/MAKEME.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ setTimeout(doIt, 5000);
4040

4141
```js
4242
function foo(func) {
43-
// What to do here?
43+
// What to
44+
func()
4445
}
4546

4647
function bar() {

Week3/homework/step2-1.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
22

33
function foo(func) {
4-
// What to do here?
5-
// Replace this comment and the next line with your code
6-
console.log(func);
4+
func();
75
}
86

97
function bar() {

Week3/homework/step2-2.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22

33
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
44
const numbers = [];
5-
6-
// Replace this comment and the next line with your code
7-
console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers);
5+
for (let i = startIndex; i <= stopIndex; i++) {
6+
numbers.push(i);
7+
if (i % 3 === 0) {
8+
threeCallback(i);
9+
}
10+
if (i % 5 === 0) {
11+
fiveCallback(i);
12+
}
13+
}
14+
console.log(`Start Index: ${startIndex}, Stop Index: ${stopIndex}`);
15+
console.log('Numbers:', numbers);
16+
return numbers;
817
}
918

1019
function sayThree(number) {
1120
// Replace this comment and the next line with your code
12-
console.log(number);
21+
console.log(`${number} is divisible by 3`);
1322
}
1423

1524
function sayFive(number) {
1625
// Replace this comment and the next line with your code
17-
console.log(number);
26+
console.log(`${number} is divisible by 3`);
1827
}
1928

2029
threeFive(10, 15, sayThree, sayFive);

Week3/homework/step2-3.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,53 @@
11
'use strict';
22

3-
// Use a 'for' loop
3+
// Use a 'for'
44
function repeatStringNumTimesWithFor(str, num) {
55
// eslint-disable-next-line prefer-const
66
let result = '';
7-
7+
for (let i = 0; i < num; i++) {
8+
result += str;
9+
}
810
// Replace this comment and the next line with your code
911
console.log(str, num, result);
1012

1113
return result;
1214
}
13-
1415
console.log('for', repeatStringNumTimesWithFor('abc', 3));
1516

1617
// Use a 'while' loop
1718
function repeatStringNumTimesWithWhile(str, num) {
18-
// eslint-disable-next-line prefer-const
1919
let result = '';
20-
20+
let i = 0;
21+
// Use a 'while' loop to concatenate the string 'num' times
22+
while (i < num) {
23+
result += str;
24+
i++;
25+
}
2126
// Replace this comment and the next line with your code
2227
console.log(str, num, result);
2328

2429
return result;
2530
}
26-
2731
console.log('while', repeatStringNumTimesWithWhile('abc', 3));
2832

2933
// Use a 'do...while' loop
3034
function repeatStringNumTimesWithDoWhile(str, num) {
31-
// eslint-disable-next-line prefer-const
3235
let result = '';
3336

34-
// Replace this comment and the next line with your code
37+
// Check if num is greater than 0 before starting the do-while loop
38+
if (num > 0) {
39+
let i = 0;
40+
do {
41+
result += str;
42+
i++;
43+
} while (i < num);
44+
}
45+
46+
// Log the information about the repetition to the console
3547
console.log(str, num, result);
3648

3749
return result;
3850
}
39-
4051
console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3));
4152

4253
// Do not change or remove anything below this line

Week3/homework/step2-4.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
22

33
function Dog() {
4-
// add your code here
4+
// Properties
5+
this.name = 'Rossy';
6+
this.color = 'white';
7+
this.numLegs = 4;
58
}
6-
79
const hound = new Dog();
10+
console.log(hound.name, hound.color, hound.numLegs);
811

912
// Do not change or remove anything below this line
1013
module.exports = hound;

Week3/homework/step2-5.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
function multiplyAll(arr) {
44
// eslint-disable-next-line
55
let product = 1;
6+
for (let i = 0; i < arr.length; i++) {
7+
for (let j = 0; j < arr[i].length; j++) {
8+
product *= arr[i][j];
9+
}
10+
}
611

712
// Replace this comment and the next line with your code
813
console.log(arr, product);

Week3/homework/step2-6.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@ const arr2d = [[1, 2], [3, 4], [5, 6]];
44
const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
55

66
function flattenArray2d(arr) {
7-
// Replace this comment and the next line with your code
8-
console.log(arr);
7+
const flattenedArray2 = arr.reduce((acc, current) => acc.concat(current), []);
8+
return flattenedArray2;
99
}
10+
// Call the function with arr2d and store the result
11+
const flattenedArray2dResult = flattenArray2d(arr2d);
12+
// Log the result
13+
console.log(flattenedArray2dResult);
1014

1115
function flattenArray3d(arr) {
12-
// Replace this comment and the next line with your code
13-
console.log(arr);
16+
return arr.flat(Infinity);
1417
}
1518

19+
// Call the function with arr3d and store the result
20+
const flattenedArray3 = flattenArray3d(arr3d);
21+
22+
// Log the result
23+
console.log(flattenedArray3); // -> [1, 2, 3, 4, 5, 6, 7
24+
// Log the result
25+
1626
console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6]
1727
console.log(flattenArray3d(arr3d)); // -> [1, 2, 3, 4, 5, 6, 7, 8]
1828

Week3/homework/step2-7.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ f2(y);
2121
console.log(y);
2222

2323
// Add your explanation as a comment here
24+
// variable x is a primitive date type number when function f1 inside val it will not affect the original value of x
25+
// variable y is object when passes to f2 function so it will affect the original value of x

Week3/homework/step3-bonus.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];
44

55
function makeUnique(arr) {
6-
// Replace this comment and the next line with your code
76
console.log(arr);
7+
const outputArray = arr.filter(function(v, i, self) {
8+
return i === self.indexOf(v);
9+
});
10+
return outputArray; // Return the modified array with duplicates removed
811
}
912

1013
const uniqueValues = makeUnique(values);

Week3/homework/step3.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

33
function createBase(base) {
4-
// Replace this comment and the next line with your code
5-
console.log(base);
4+
return function(number) {
5+
return base + number;
6+
};
67
}
78

89
const addSix = createBase(6);

0 commit comments

Comments
 (0)