
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

240 Views
We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument.The function should then construct and return a new array based on the original array.The new array should contain all those elements from the original array whose value was equal to the index they were placed on.Note that we have to check the value and index using 1-based index and not the traditional 0- based index.For example −If the input array is −const arr = [45, 5, 2, 4, 6, 6, 6];Then the output should be −const output = ... Read More

391 Views
We are required to write a JavaScript function that takes in an array of Integers as the first and the only argument.The function should then iterate through the array and pick that largest number from the array which only appeared once in the array. After that, return this number and if there is no unique number in the array, we should return -1.We are also told that the maximum value of any array element will not exceed 100 and will be greater than 0 which mean −0 < arr[i] < 101for all i within the array index.For example −If the ... Read More

172 Views
We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument. The function should return true if all the numbers in the array appear only once (i.e., all the numbers are unique), and false otherwise.For example −If the input array is −const arr = [12, 45, 6, 34, 12, 57, 79, 4];Then the output should be −const output = false;because the number 12 appears twice in the array.ExampleThe code for this will be − Live Democonst arr = [12, 45, 6, 34, 12, 57, 79, 4]; const containsAllUnique = (arr ... Read More

621 Views
We are required to write a JavaScript function that takes in an array of integers, arr, as the first argument and a number, num (num < length of arr) as the second argument. The function should construct and return a new array that contains the average of all possible num contiguous numbers of the array.For example −If the input array and the number are −const arr = [1, 2, 3, 4, 5]; const num = 2;Then the output should be −const output = [1.5, 2.5, 3.5, 4.5];because the possible continuous windows of size two are (1, 2), (2, 3), (3, ... Read More

584 Views
Suppose, we have an array of objects that contains information about some students and the marks scored by them over a period of time like this −const marks = [ { id: 231, score: 34 }, { id: 233, score: 37 }, { id: 231, score: 31 }, { id: 233, score: 39 }, { id: 231, score: 44 }, { id: 233, score: 41 }, { id: 231, score: 38 }, { id: 231, score: 31 }, { id: 233, score: 29 }, { id: 231, score: 34 }, ... Read More

486 Views
We are required to write a JavaScript function that takes in an array of Integers as the first and the only argument. The function should then construct and return a new array that contains only those elements from the original array that contains an even number of digits.For example −If the input array is −const arr = [12, 6, 123, 3457, 234, 2];Then the output should be −const output = [12, 3457];ExampleThe code for this will be − Live Democonst arr = [12, 6, 123, 3457, 234, 2]; const findEvenDigitsNumber = (arr = []) => { const res = []; ... Read More

304 Views
We are required to write a JavaScript function that takes in a number, num as the only argument. The function should first construct an array of n elements based on the following rule −arr[i] = (2 * i) + 1;Therefore, if the input number is 5, then the array should be −const arr = [1, 3, 5, 7, 9];Our function is supposed to calculate and return the minimum number of steps it should take so that all the elements of the array become equal.Let us now define one step −One valid step consists of choosing any two numbers from the ... Read More

333 Views
We are required to write a JavaScript function that takes in a binary array (an array that consists of 0 or 1 only) as the only argument.The function should find the length of that consecutive subarray of the array that consists of only 1 and return it.For example −If the input array is −const arr = [1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1];Then the output should be −const output = 4;We will use the sliding window algorithm to capture the largest window (largest in size) that consists of only 1.ExampleThe code for this ... Read More

160 Views
We are required to write a JavaScript function that takes in four arguments. The four arguments will all be arrays of exactly two numbers representing the coordinates of four vertices of a quadrilateral or any figure (closed or unclosed) on a plane.The task of our function is to determine whether or not the four vertices form a square.If they do form a square, we should return true, false otherwise.For example −If the input coordinates are −const c1 = [1, 0]; const c2 = [-1, 0]; const c3 = [0, 1]; const c4 = [0, -1];Then the output should be −const ... Read More

440 Views
We are required to write a JavaScript function that takes in three arrays of integers all sorted in an increasing order. The function should then construct and return an array that contains only those elements that present in all three arrays.For example −If the input arrays are −const arr1 = [4, 7, 8, 11, 13, 15, 17]; const arr2 = [1, 3, 4, 13, 18]; const arr3 = [2, 4, 7, 8, 9, 10, 13];Then the output should be −const output = [4, 13];ExampleThe code for this will be − Live Democonst arr1 = [4, 7, 8, 11, 13, 15, 17]; ... Read More