-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask questions.txt
73 lines (54 loc) · 1.99 KB
/
Task questions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
1. Write a JavaScript function to check whether an `input` is an array or not.
Test Data :
console.log(is_array('w3resource'));
console.log(is_array([1, 2, 4, 0]));
Expected Output:-
false
true
2. Write a JavaScript function to clone an array.
Test Data :
console.log(array_Clone([1, 2, 4, 0]));
Expected Output:-
[1, 2, 4, 0]
3. Write a JavaScript function to get the first element of an array. Passing a parameter 'n' will return the first 'n' elements of the array.
Test Data :
console.log(first([7, 9, 0, -2]));
console.log(first([],3));
console.log(first([7, 9, 0, -2],3));
console.log(first([7, 9, 0, -2],6));
console.log(first([7, 9, 0, -2],-3));
Expected Output :
7
[]
[7, 9, 0]
[7, 9, 0, -2]
[]
4. Write a simple JavaScript program to join all elements of the following array into a string.
Sample array : myColor = ["Red", "Green", "White", "Black"];
Expected Output :
"Red,Green,White,Black"
"Red,Green,White,Black"
"Red+Green+White+Black"
5.There are two arrays with individual values, write a JavaScript program to compute the sum of each individual index value from the given arrays.
Sample array :
array1 = [1,0,2,3,4];
array2 = [3,5,6,7,8];
Expected Output :
[4, 5, 8, 10, 12]
6.Write a JavaScript function to remove a specific element from an array.
Test data :
console.log(remove_array_element([2, 5, 9, 6], 5));
[2, 9, 6]
7.Write a JavaScript function to generate an array of specified length, filled with integer numbers, increase by one from starting position.
Test Data :
console.log(array_range(1, 4));
[1, 2, 3, 4]
8. Write a JavaScript script to empty an array keeping the original.
9. Write a JavaScript function to get nth largest element from an unsorted array.
Test Data :
console.log(nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4));
89
10. Write a JavaScript function to get nth largest element from an unsorted array.
Test Data :
console.log(nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4));
89