
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

429 Views
Let’s say, we are required to write a function, say isSame() that accepts a nested object and returns a boolean depending on the fact whether or not all the keys have the same values. When saying all the keys we mean all the last keys like if a key has a nested object as its value, we are required to traverse to the end of the nested object and check for that value.For example − If the object is −const obj = { a: 1, b: 1, c: { aa: 1 } };Then ... Read More

268 Views
We are required to write a function, say minMax() that takes in an array of Numbers and rearranges the elements such that the greatest element appears first followed by the smallest elements then the second greatest element followed by second smallest element and so on.For example −// if the input array is: const input = [1, 2, 3, 4, 5, 6, 7] // then the output should be: const output = [7, 1, 6, 2, 5, 3, 4]So, let’s write the complete code for this function −Exampleconst input = [1, 2, 3, 4, 5, 6, 7]; const minMax = arr ... Read More

209 Views
Consider we have an array of Numbers that looks like this −const array = [3.1, 1, 2.2, 5.1, 6, 7.3, 2.1, 9];We are required to write a function that counts how many of the elements are in the array below / above a given number.For example, if the number is 5.25, the answer should be the following 5 elements, (3.1, 1, 2.2, 5.1, 2.1)and 3 elements above it −(6, 7.3, 9)Note − If any element is equal to the provided number, it should be counted as above the number.So, let’s write the code for this function −Exampleconst array = [3.1, ... Read More

1K+ Views
We have an array of objects like this −const arr = [ { value: 12, gap: 1 }, { value: 13, gap: 1 }, { value: 14, gap: 1 }, { value: 15, gap: 1 }, { value: 19, gap: 2 }, { value: 21, gap: 1 }, { value: 22, gap: 1 }, { value: 23, gap: 1 }, { value: 27, gap: 1 }, { value: 31, gap: 4 }, { value: 35, gap: 4 }, { value: 39, gap: 4 }, { value: 43, ... Read More

265 Views
We are required to write a function that takes in a string as the first and the only argument and constructs an object with its keys based on the unique characters of the string and value of each key being defaulted to 0.For example −// if the input string is: const str = 'hello world!'; // then the output should be: const obj = {"h": 0, "e": 0, "l": 0, "o": 0, " ": 0, "w": 0, "r": 0, "d": 0, "!": 0};So, let’s write the code for this function −Exampleconst str = 'hello world!'; const stringToObject = str => ... Read More

1K+ Views
Let’s say, we have an array of string / number literals that contains some duplicate values like this −const array = ['day', 'night', 'afternoon', 'night', 'noon', 'night', 'noon', 'day', 'afternoon', 'day', 'night'];We are required to write a function groupSimilar() that takes in this array and returns a new array where all the repeating entries are group together in a subarray as the first element and their total count in the original array as the second element.So, for this example, the output should be −[ [ 'day', 3 ], [ 'night', 4 ], [ 'afternoon', 2 ], ... Read More

185 Views
We are required to write a function that, given an array arr and a number n, returns the array with elements repeating no more than n times. And we have to do all this without disturbing the indices of desired elements. So, let’s write the code for this function, We will keep the count of all the elements in a hashmap and during iteration whenever the count of any element exceeds the maximum count we will splice that element. The code for this will be −Exampleconst arr = [7, 26, 21, 41, 43, 2, 26, 24, 10, 26, 10, 10, ... Read More

461 Views
We are required to write an array function, say findMiddle that returns the middlemost element of the array without accessing its length property and without using any kind of built-in loops. If the array contains an odd number of elements, we return the one, middlemost element, or if the array contains an even number of elements, we return an array of two middlemost elements.So, let’s write the code for this function. As you’ve already guessed, we will be making use of recursion to find these elements. The code for the recursive function will be −Exampleconst arr = [1, 2, 3, ... Read More

126 Views
By starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite amount of new numbers can be produced. We are required to write a function that, given a number, tries to find a sequence of such additions and multiplications that produce that number. And returns a boolean based on the fact whether or not there exists any such sequenceFor example, The number 13 could be reached by first multiplying by 3 and then adding 5 twice, so the function should return true for 13. Whereas the number 15 cannot be reached at all, so ... Read More

774 Views
We are required to write a function chunk() that takes in an array arr of string / number literals as the first argument and a number n as second argument.We are required to return an array of n subarrays, each of which contains at most arr.length / n elements. And the distribution of elements should be like this −The first element goes in the first subarray, second in second, third in third and so on. Once we have one element in each subarray, we again start with filling the first subarray with its second element. Similarly, when all subarrays have ... Read More