
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 10483 Articles for Web Development

2K+ Views
The Hex (Hexadecimal) code is a six-digit code and a three-byte hexadecimal number that is used to represent the colors. These three bytes represent RGB which means the amount of red, green, and blue in a particular shade of a color. Each byte will represent a number in the range 00 to FF (Hexadecimal notation) or 0 to 255 in decimal notation. This indicates the intensity of each of the color components from 0 to 255. The following are the functions to be used for generating random hex codes − Math.random() is used to get the number randomly in the ... Read More

953 Views
An Array in JavaScript is a single variable where it can store different elements. These elements are stored at contiguous memory locations. Array elements can be accessed with the help of index numbers. The index numbers will start from 0. Syntax Below is the basic declaration of the array in JavaScript − Cosnt cars = [Maruti, Hyundai, Honda]; We need to return an array of all the indices of minimum elements in a JavaScript array Let’s look into the input-output scenario Assume there is an integer array where the minimum element is repeated more than once. We need to ... Read More

13K+ Views
In this article, the given task is to get the factorial of a number in JavaScript. What is the factorial of a number? The multiplication of all positive integers smaller than or equal to n gives the factorial of a non-negative integer. For example, assume the non-negative integer is 4 and the factorial of 4 will be 4*3*2*1 which is equal to 24. The symbol of factorial is represented by "!". so it will be (4!). The value of 0! Will be 1 as 0 is not a positive integer. The mathematical formula of factorial ("n!") This is ... Read More

1K+ Views
Given there is an array with some empty indices and need to remove those empty indices from array. Let’s look into the input output scenarios – Consider there is an array with some empty indices. Now we need to exclude them and return the elements which are having only truthy values. Array = [22, 45, , 56, 71, , 10]; Output = [22, 45, 56, 71, 10] As we can see in the output, the indices which are empty in the array got removed. We can achieve the above task by using several methods, let’s look into the ... Read More

224 Views
Suppose, we have two arrays like these −const arr1 = ['d', 'a', 'b', 'c'] ; const arr2 = [{a:1}, {c:3}, {d:4}, {b:2}];We are required to write a JavaScript function that accepts these two arrays. The function should sort the second array according to the elements of the first array.We have to sort the keys of the second array according to the elements of the first array.Therefore, the output should look like −const output = [{d:4}, {a:1}, {b:2}, {c:3}];Therefore, let’s write the code for this function −ExampleThe code for this will be −const arr1 = ['d', 'a', 'b', 'c'] ; const ... Read More

461 Views
Suppose, we have two arrays like these −const arr1 = [1, 2, 3, 4, 5, 6]; const arr2 = [9, 8, 7, 5, 8, 3];We are required to write a JavaScript function that takes in such two arrays and returns an array of absolute difference between the corresponding elements of the array.So, for these arrays, the output should look like −const output = [8, 6, 4, 1, 3, 3];We will use a for loop and keep pushing the absolute difference iteratively into a new array and finally return the array.Therefore, let’s write the code for this function −ExampleThe code for ... Read More

112 Views
We are required to write a JavaScript function that takes in a number, say n, and an array of two numbers that represents a range. The function should return an array of n random elements all lying between the range provided by the second argument.Therefore, let’s write the code for this function −ExampleThe code for this will be −const num = 10; const range = [5, 15]; const randomBetween = (a, b) => { return ((Math.random() * (b - a)) + a).toFixed(2); }; const randomBetweenRange = (num, range) => { const res = []; for(let i = ... Read More

128 Views
Suppose, we have a string with digits like this −const str = '11222233344444445666';We are required to write a JavaScript function that takes in this string and returns an object that represents the count of each number in the string.So, for this string, the output should be −const output = { "1": 2, "2": 4, "3": 3, "4": 7, "5": 1, "6": 3 };Therefore, let’s write the code for this function −ExampleThe code for this will be −const str = '11222233344444445666'; const mapString = str => { const map = {}; for(let i ... Read More

154 Views
We are required to write a JavaScript function that takes in an array of numbers that may contain some duplicate numbers. Our function should return the sum of all the unique elements (elements that only appear once in the array) present in the array.For exampleIf the input array is −const arr = [2, 5, 5, 3, 2, 7, 4, 9, 9, 11];Then the output should be 25.We will simply use a for loop, iterate the array and return the sum of unique elements.ExampleThe code for this will be −const arr = [2, 5, 5, 3, 2, 7, 4, 9, 9, ... Read More

363 Views
Suppose, we have an array of objects like this −const arr = [{a: 2, b: 5, c: 6}, {a:3, b: 4, d:1}, {a: 1, d: 2}];Each object is bound to have unique in itself (for it to be a valid object), but two different objects can have the common keys (for the purpose of this question).We are required to write a JavaScript function that takes in one such array and returns an object with all the unique keys present in the array and their values cumulative sum as the value.So, the resultant object should look like −const output = {a: ... Read More