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

Skip to content

Commit 970e495

Browse files
Done JS2 HWW3
1 parent bab3fb0 commit 970e495

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

Week3/homework/js-exercices/addSix.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
function createBase(numb) {
3+
var compt=9;
4+
return function () {compt += numb; numb=numb+3; return compt; }
5+
}
6+
7+
const addSix = createBase(6);
8+
9+
// Put here your function calls...
10+
11+
console.log(addSix());
12+
console.log(addSix());
13+
console.log(addSix());
14+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Snippet
2+
var x = 9;
3+
function f1(val) {
4+
val = val + 1;
5+
return val;
6+
}
7+
f1(x);
8+
console.log(x);
9+
10+
const y = { x: 9 };
11+
function f2(val) {
12+
val.x = val.x + 1;
13+
return val;
14+
}
15+
f2(y);
16+
console.log(y);
17+
18+
/*
19+
1-"x" is a primitif value, it will not change when we use it in argument of the function. when "f1" receive the argument,
20+
make a new memory in the computer keep there the value of argument and modifi that value in the new memory.
21+
the new memory will be free when "f1" finish to execute. the console.log(x) will display 9.
22+
2-"y" is not a primitif value, it will change when we use it in argument of the function. when "f2" receive the argument,
23+
the parameter point at the same memory than the argument and modifi that value in the memory.
24+
the value of the memory of argument will be change when "f2" finish to execute. the console.log(x) will display x:10.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
// Snippet
3+
let a = 10;
4+
const x = (function() {
5+
a = 12;
6+
return function() {
7+
alert(a);
8+
};
9+
})();
10+
11+
x();
12+
/* This function will be semi execute automaticaly. that why we use parenrhese at 3 times. we declare and initialize two times "a" variable, the first is globale for all functions and second is local for the first function but it's global for the second function who is inside also the first function. In the second function we alert "a" variable, the function go up and check the first "a" variable that going to find and it will alert "12", value of the locale variable.*/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
function lotteryThreeFive (valStart, valFinale, divBy3, divBy5){
3+
let myArray=[valStart];
4+
for(let i=1; i<=valFinale-valStart; i++){
5+
myArray.push(valStart+i);
6+
}
7+
console.log(myArray);
8+
for(let elements of myArray){
9+
if((elements%3)===0){
10+
divBy3(elements);
11+
console.log("------------------");
12+
}
13+
if((elements%5)===0){
14+
divBy5(elements);
15+
console.log("------------------");
16+
}
17+
}
18+
// return myArray;
19+
}
20+
function divByTree(element){
21+
console.log(element+" is divible by 3")
22+
}
23+
function divByFive(element){
24+
console.log(element+" is divible by 5")
25+
}
26+
lotteryThreeFive(0,15,divByTree, divByFive);
27+
28+
;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const letter = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];
4+
function removeDuplicates(array){
5+
6+
for( let element of array){
7+
let run=(array.indexOf(element)+1);
8+
for(run; run<array.length; run++){
9+
if(array[run]==element){
10+
array.splice(run, 1);
11+
}
12+
}
13+
}
14+
return array;
15+
}
16+
console.log(removeDuplicates(letter));
17+

0 commit comments

Comments
 (0)