
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

382 Views
We are required to write a JavaScript function that takes in an array of literals which may contain some duplicate values.The function should return an array of all those elements that are repeated for the least number of times.For example− If the input array is −const arr = [1, 1, 2, 2, 3, 3, 3];Then the output should be −const output = [1, 2];because 1 and 2 are repeated for the least number of times (2)Exampleconst arr = [1, 1, 2, 2, 3, 3, 3]; const getLeastDuplicateItems = (arr = []) => { const hash = Object.create(null); let ... Read More

159 Views
Suppose we have an array of strings like this −const arr = [ 'type=A', 'day=45' ];We are required to write a JavaScript function that takes in one such array. The function should construct an object based on this array. The object should contain a key/value pair for each string in the array.For any string, the part before '=' becomes the key and the part after it becomes the value.Exampleconst arr = [ 'type=A', 'day=45' ]; const arrayToObject = (arr = []) => { const obj = {}; for (let i = 0; i < arr.length; i++) { ... Read More

832 Views
We are given an array of size n, and we are required to find the majority element. The majority element is the element that appears more than [ n/2 ] times.Exampleconst arr = [2, 4, 2, 2, 2, 4, 6, 2, 5, 2]; const majorityElement = (arr = []) => { const threshold = Math.floor(arr.length / 2); const map = {}; for (let i = 0; i < arr.length; i++) { const value = arr[i]; map[value] = map[value] + 1 || 1; if (map[value] > threshold) return value }; return false; }; console.log(majorityElement(arr));OutputAnd the output in the console will be −2

321 Views
We are required to write an Array function (functions that lives on Array.prototype object). The function should take in a start index and an end index and it should sum all the elements from start index to end index in the array (including both start and end)Exampleconst arr = [1, 2, 3, 4, 5, 6, 7]; const sumRange = function(start = 0, end = 1){ const res = []; if(start > end){ return res; }; for(let i = start; i

1K+ Views
We are given two strings str1 and str2, we are required to write a function that checks if str1 is a subsequence of str2.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters.For example, "ace" is a subsequence of "abcde" while "aec" is notExampleconst str1 = 'ace'; const str2 = 'abcde'; const isSubsequence = (str1, str2) => { let i=0; let j=0; while(i

162 Views
We are required to write a JavaScript function that takes in an array of objects of dates like this −const arr = [ {date: "2016-06-08 18:10:00"}, {date: "2016-04-26 20:01:00"}, {date: "2017-02-06 14:38:00"}, {date: "2017-01-18 17:30:21"}, {date: "2017-01-18 17:24:00"} ];We are required to write a JavaScript function that takes in one such array. The function should then sort the array according to the date property of the objects.Exampleconst arr = [ {date: "2016-06-08 18:10:00"}, {date: "2016-04-26 20:01:00"}, {date: "2017-02-06 14:38:00"}, {date: "2017-01-18 17:30:21"}, {date: "2017-01-18 17:24:00"} ]; const sortByTime = (arr ... Read More

2K+ Views
Obtaining the sum of two objects in JavaScript having the same properties Obtaining the sum of two objects in JavaScript having the same properties is a basic implementation with JavaScript objects. To do this, we are required to write a JavaScript function that takes in two such objects. The function should sum the values of identical properties into a single property. In JavaScript, objects are data structures that allow you to store collections of key-value pairs. Sometimes, you might need to sum the values of two objects that have the same properties. This article will guide you on how to ... Read More

720 Views
Suppose, we have the following array of objects −const arr = [ { "date" : "2010-01-01", "price" : 30 }, { "date" : "2010-02-01", "price" : 40 }, { "date" : "2010-03-01", "price" : 50 }, { "date" : "2010-01-01", "price2" : 45 }, { "date" : "2010-05-01", "price2" : 40 }, { "date" : "2010-10-01", ... Read More

4K+ Views
Suppose, we have an array of objects like this −const arr = [{ "value": 10, "id": "111", "name": "BlackCat", }, { "value": 10, "id": "111", "name": "BlackCat", }, { "value": 15, "id": "777", "name": "WhiteCat", }];We are required to write a JavaScript function that takes in one such array.The function should then merge all those objects together that have the common value for "id" property.Therefore, for the above array, the output should look like −const output = [{ "value": 10, "id": "111", "name": "BlackCat", "count": 2, ... Read More

161 Views
We are required to write a JavaScript function that takes in two strings, say str1 and str2. We are required to determine whether or not the second string is a rotated version of the first string.For example− If the input strings are −const str1 = 'abcde'; const str2 = 'cdeab';Then the output should be true because str2 is indeed made by shifting 'ab' to the end of string in str1.Exampleconst str1 = 'abcde'; const str2 = 'cdeab'; const isRotated = (str1, str2) => { if(str1.length !== str2.length){ return false }; if( (str1.length || str2.length) ... Read More