Skip to content

Commit c56cf31

Browse files
committed
most reapeated functions questions
1 parent c70369c commit c56cf31

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

JavaScript Interview/demo.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
/*
3+
Empty the array splice method
4+
5+
*/
6+
const arr=[1,2,3]
7+
arr.splice(0,arr.length)
8+
console.log(arr)//[]
9+
10+
11+
12+
/*
13+
Map Method- return the new array with modication
14+
*/
15+
const a=[1,2,3]
16+
const b=a.map((n)=>n*2)
17+
console.log(b)//[2,4,6]
18+
19+
20+
/*
21+
Reduce method- return single value
22+
*/
23+
const x=[1,2,3]
24+
const y=x.reduce((acc,num)=>acc*num)
25+
console.log(y)//6
26+
27+
28+
/*
29+
Filter Method-Return the new array to filter
30+
*/
31+
32+
const p=[1,2,3]
33+
const q=p.filter(item=>item>1)
34+
console.log(q)//[2,3]
35+
36+
37+
/*
38+
Replace method New Line
39+
*/
40+
const abc="Hello World"
41+
const xyz=abc.replace(" ","\n")
42+
console.log(xyz)
43+
44+
/*
45+
Output
46+
47+
Hello
48+
World
49+
*/
50+
51+
/*
52+
53+
Find method to find a specific value
54+
*/
55+
const v=[1,2,3]
56+
const vb=v.find(num=>num>2)
57+
console.log(vb)//3
58+
59+
60+
/*
61+
62+
*/
63+
function infiniteocc(val1){
64+
return function(val2){
65+
if(!val2){
66+
return val1
67+
}
68+
return infiniteocc(val1+val2)
69+
}
70+
}
71+
console.log(infiniteocc(1)(2)())

0 commit comments

Comments
 (0)