Skip to content

Commit c312d68

Browse files
committed
freecode camp solutions added
1 parent 89f7db0 commit c312d68

File tree

6 files changed

+82
-0
lines changed

6 files changed

+82
-0
lines changed

freecodecamp/arrowFunction.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Rewrite the function assigned to the variable magic which returns a new Date() to use arrow function syntax.
3+
Also, make sure nothing is defined using the keyword var.
4+
*/
5+
6+
/*var magic = function() {
7+
return new Date();
8+
};*/
9+
10+
const magic = () => {
11+
return new Date();
12+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//Rewrite the myConcat function which appends contents of arr2 to arr1 so that the function uses arrow function syntax.
2+
3+
// var myConcat = function(arr1, arr2) {
4+
// return arr1.concat(arr2);
5+
// };
6+
7+
const myConcat = (arr1, arr2) => {
8+
return arr1.concat(arr2);
9+
};
10+
11+
console.log(myConcat([1, 2], [3, 4, 5]));

freecodecamp/defaultParameters.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//Set Default Parameters for Your Functions
2+
//Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified.
3+
4+
// Only change code below this line
5+
const increment = (number, value = 1) => number + value;
6+
// Only change code above this line

freecodecamp/freezeObject.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
function freezeObj() {
3+
const MATH_CONSTANTS = {
4+
PI: 3.14,
5+
};
6+
// Only change code below this line
7+
Object.freeze(MATH_CONSTANTS);
8+
9+
// Only change code above this line
10+
try {
11+
//Below line will not affect the code as the object is freezed
12+
MATH_CONSTANTS.PI = 99;
13+
} catch (ex) {
14+
console.log(ex);
15+
}
16+
return MATH_CONSTANTS.PI;
17+
}
18+
19+
const PI = freezeObj();
20+
console.log(PI);

freecodecamp/mutateArray.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//An array is declared as const s = [5, 7, 2]. Change the array to [2, 5, 7] using various element assignments.
2+
const s = [5, 7, 2];
3+
function editInPlace() {
4+
// Only change code below this line
5+
6+
// Using s = [2, 5, 7] would be invalid
7+
var l = s.length;
8+
var t = s[l - 1];
9+
for (var i = 0; i < l; i++) {
10+
s[l - i - 1] = s[l - i - 2];
11+
}
12+
s[0] = t;
13+
// Only change code above this line
14+
}
15+
editInPlace();
16+
console.log(s);

freecodecamp/scope.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//Block scope and function scope
2+
function checkScope() {
3+
let i = "function scope";
4+
if (true) {
5+
let i = "block scope";
6+
console.log("Block scope i is: ", i);
7+
}
8+
console.log("Function scope i is: ", i);
9+
return i;
10+
}
11+
checkScope();
12+
13+
/*Output
14+
D:\Code\js\Javascript\freecodecamp>node scope.js
15+
Block scope i is: block scope
16+
Function scope i is: function scope
17+
*/

0 commit comments

Comments
 (0)