You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## JavaScript interview code challenges on Collections - challenges
6
-
7
-
1.[Write a function which can concatenate 2 arrays. If only one array is passed it will duplicate it](#Q1)
8
-
1.[Write a program to replace 3 center elements of the 1st array by center 3 elements of the 2nd array](#Q2)
9
-
1.[Sort the given array of integers in ascending or descending order](#Q3)
10
-
1.[Sort the given array of objects in ascending order according the authors lastname](#Q4)
11
-
1.[Square all the positive numbers of the array and return the output array](#Q5)
12
-
1.[Write a code to generate an array with range of numbers and shuffle them](#Q6)
13
-
1.[Check if the user with the name "John" exists in the array of objects](#Q7)
14
-
1.[Generate an array of objects with properties id and full name from an array of objects where each object will have id, firstname and lastname](#Q8)
15
-
1.[Write a program to calculate the sum of all the values of an array](#Q9)
16
-
1.[Get the maximum value from a numbers array along with its index](#Q10)
17
-
1.[Find the number of occurences of minimum value in the numbers list](#Q11)
18
-
1.[Create an array of length n with all the values of it set to 10](#Q12)
19
-
1.[Write the code to remove the duplicates from the array](#Q13)
20
-
1.[Design a flat function which flattens an array to any depth](#Q14)
21
-
1.[Check if all the students of have passed or not (40 is the pass marks)](#Q15)
22
-
1.[Get the average of all the salaries which is greater than 10000 from the department of "IT" from the array of objects)](#Q16)
23
-
1.[Extract the list of all the elements from the list of numbers given in 2 arrays](#Q17)
24
-
1.[Get the list of all distinct elements which are present in both list of numbers](#Q18)
25
-
1.[Extract list of elements present only in the first list given.](#Q19)
26
-
1.[Create a function named "average" which can calculate the average of an array and should be available to be called from any Array object.](#Q20)
27
-
1.[Write a code to eliminate duplicate objects in an array where each object has an 'id' property which can be used to identify the object and the duplicate object with lower rank to be removed](#Q21)
28
-
1.[Create an array which will only accept string values. (Homogeneous array of strings)](#Q22)
29
-
1.[Create a Proxy object through which the array can be accessed as usual but also allow to access the values through negative indices](#Q23)
30
-
31
-
---
32
-
33
-
#### Q1
34
-
### Write a function which can concatenate 2 arrays. If only one array is passed it will duplicate it
5
+
<h2align="center">JavaScript challenges on Collections - challenges</h2>
6
+
7
+
<br>
8
+
9
+
### Q. Write a function which can concatenate 2 arrays. If only one array is passed it will duplicate it
35
10
36
11
- Function can take 2 arguments which concatenates arrays
37
12
- 2nd array parameter can be defaulted to 1st array if the value is not passed
@@ -63,8 +38,7 @@ When 2nd argument is not passed, the case is same as duplicating the array
63
38
64
39
<br />
65
40
66
-
#### Q2
67
-
### Write a program to replace 3 center elements of the 1st array by center 3 elements of the 2nd array
41
+
### Q. Write a program to replace 3 center elements of the 1st array by center 3 elements of the 2nd array
68
42
69
43
-`slice` method on array can be used to fetch the values of range in the array
70
44
-`splice` method on array can be used to replace the value of range in the array
@@ -83,8 +57,7 @@ The center most 3 values of array 'a' is replaced by 'b'
83
57
84
58
<br />
85
59
86
-
#### Q3
87
-
### Sort the given array of integers in ascending or descending order
60
+
### Q. Sort the given array of integers in ascending or descending order
88
61
89
62
-`sort` method sorts the elements of an array in place and returns the sorted array
90
63
- It receives a function as an argument, which is used for comparision
@@ -102,8 +75,7 @@ If function is not passed an argument, default sorting will happen
102
75
103
76
<br />
104
77
105
-
#### Q4
106
-
### Sort the given array of objects in ascending order according the authors lastname
78
+
### Q. Sort the given array of objects in ascending order according the authors lastname
107
79
```js
108
80
// Example
109
81
constbooks= [
@@ -128,8 +100,7 @@ Returning a true or false will not work as the algorithm expects an integer valu
128
100
129
101
<br />
130
102
131
-
#### Q5
132
-
### Square all the positive numbers of the array and return the output array
103
+
### Q. Square all the positive numbers of the array and return the output array
133
104
134
105
-`filter` is the method on Array which can be used to filter. It receives a function which can return boolean to filter the elements
135
106
-`map` is the method on Array which can be used to map the values to new values. It receives a function which can return the modified value
### Extract list of elements present only in the first list given.
370
+
### Q. Extract list of elements present only in the first list given.
414
371
415
372
- The only present elements of 1st list will be the result when all the elements of 1st list not present in the 2nd are chosen
416
373
@@ -425,8 +382,7 @@ Elements of 2nd list only can be obtained by checking for all the elements of li
425
382
426
383
<br />
427
384
428
-
#### Q20
429
-
### Create a function named "average" which can calculate the average of an array and should be available to be called from any Array object.
385
+
### Q. Create a function named "average" which can calculate the average of an array and should be available to be called from any Array object.
430
386
431
387
- The function added to Array prototype are accessible to all the objects of Array
432
388
@@ -443,8 +399,7 @@ Array.prototype.average = function (){
443
399
444
400
<br />
445
401
446
-
#### Q21
447
-
### Write a code to eliminate duplicate objects in an array where each object has an 'id' property which can be used to identify the object and the duplicate object with lower rank to be removed
402
+
### Q. Write a code to eliminate duplicate objects in an array where each object has an 'id' property which can be used to identify the object and the duplicate object with lower rank to be removed
0 commit comments