Skip to content

Commit 7cf46a5

Browse files
committed
interviw questions day 1 js
1 parent e85e811 commit 7cf46a5

6 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
/*
4+
acc curr
5+
1 * 2 2
6+
2 * 3 6
7+
6* 4 24
8+
and so on
9+
10+
*/
11+
12+
13+
const arr = [1, 2, 3, 4, 5, 6]
14+
15+
const result = arr.reduce((acc, curr) => acc * curr)
16+
17+
console.log(result)//720
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const arr = [2, 3, 4, 5, 6]
2+
3+
//arr.length = 0;
4+
//arr = [];
5+
arr.splice(0, 5)//// Removes 5 elements starting from index 0
6+
console.log(arr)

JavaScript Interview/Day 1/fun1.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
console.log(abc())
2+
3+
function abc(){
4+
console.log("pqr") // this function doest not returning anything thats why undefined
5+
}
6+
7+
abc()
8+
// pqr undefined pqr

JavaScript Interview/Day 1/fun2.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
3+
4+
The code demonstrates the use of a higher-order function and function chaining.
5+
*/
6+
7+
8+
9+
function abc(){
10+
return function(){
11+
console.log("Rahul")
12+
}
13+
}
14+
15+
console.log(abc()())//rahul undefined
16+
17+
//abc()() rahul

JavaScript Interview/Day 1/fun3.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function infiniteCurry(val1){
2+
return function(val2){
3+
if(!val2){
4+
return val1;
5+
}
6+
return infiniteCurry(val1 + val2)
7+
}
8+
}
9+
10+
console.log(infiniteCurry(1)(2)(3)(4)(5)(6)())//21

JavaScript Interview/Day 1/var.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const c = {
2+
name: "rahul"
3+
}
4+
5+
const d=c; //adrees object will be copied there
6+
c.name = "kumar"
7+
console.log(d.name)//kumar

0 commit comments

Comments
 (0)