
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

2K+ Views
Let’s say e have a parentArray that contains many sub arrays each of the same size, each sub array is an array of objects containing two properties: key and value. Within a subarray it is confirmed that two objects cannot have the same key but all subarrays have the same pair of n keys where n is the size of the sub array.Our job is to prepare an object with key as key of objects and value being an array that contains all the values for that particular key.Here is our sample parent array −const parentArray = [[ { ... Read More

6K+ Views
Let’s say, we have an object with other objects being its property value, it is nested to 2-3 levels or even more.Here is the sample object −const people = { Ram: { fullName: 'Ram Kumar', details: { age: 31, isEmployed: true } }, Sourav: { fullName: 'Sourav Singh', details: { age: 22, isEmployed: false } }, Jay: { ... Read More

147 Views
We have an array of objects that contains data about some cars. The array is given as follows −const cars = [{ company: 'Honda', type: 'SUV' }, { company: 'Hyundai', type: 'Sedan' }, { company: 'Suzuki', type: 'Sedan' }, { company: 'Audi', type: 'Coupe' }, { company: 'Tata', type: 'SUV' }, { company: 'Morris Garage', type: 'Hatchback' }, { company: 'Honda', type: 'SUV' }, { company: 'Tata', type: 'Sedan' }, { company: 'Honda', type: 'Hatchback' }];We are required to write a program ... Read More

2K+ Views
We need to write a function that reads a string and converts the odd indexed characters in the string to upperCase and the even ones to lowerCase and returns a new string.Full code for doing the same will be −Exampleconst text = 'Hello world, it is so nice to be alive.'; const changeCase = (str) => { const newStr = str .split("") .map((word, index) => { if(index % 2 === 0){ return word.toLowerCase(); }else{ return word.toUpperCase(); } }) ... Read More

865 Views
Let’s say, we will be given an array of numbers / strings that contains some duplicate entries, all we have to do is to return the frequency of each element in the array. Returning an object with element as key and it’s value as frequency would be perfect for this situation.We will iterate over the array with a forEach() loop and keep increasing the count of elements in the object if it already exists otherwise we will create a new property for that element in the object.And lastly, we will return the object.The full code for this problem will be ... Read More

501 Views
We are required to write a function, say breakString() that takes in two arguments: First, the string to be broken and second, a number that represents the threshold count of characters after reaching which we have to repeatedly add line breaks in place of spaces.For example −The following code should push a line break at the nearest space if 4 characters have passed without a line break −const text = 'Hey can I call you by your name?'; console.log(breakString(text, 4));Expected Output −Hey can I call you by your name?So, we will iterate over the with a for loop, we will ... Read More

1K+ Views
We have an array that contains some numbers and some strings. We are required to sort the array such that the numbers gets sorted and get placed before every string and then the string should be placed sorted alphabetically.For example −This array after being sortedconst arr = [1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9];Should look like this −[1, 6, 7, 9, 47, 'afv', 'bdf', 'fdf', 'svd']So, let’s write the code for this −Exampleconst arr = [1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9]; const sorter = (a, b) => { if(typeof a === 'number' && typeof ... Read More

108 Views
We are required to write a function validate() that takes in a string as one and only argument and returns another string that has all ‘a’ and ‘i’ replaced with ‘@’ and ‘!’ respectively.It’s one of those classic for loop problems where we iterate over the string with its index and construct a new string as we move through.The code for the function will be −Exampleconst string = 'Hello, is it raining in Amsterdam?'; const validate = (str) => { let validatedString = ''; for(let i = 0; i < str.length; i++){ if(str[i] === 'a'){ ... Read More

274 Views
A number is a gapful number when −It has at least three digits, andIt is exactly divisible by the number formed by putting its first and last digits togetherFor example −The number 1053 is a gapful number because it has 4 digits and it is exactly divisible by 13. Similarly, 135 is a gapful number because it has 3 digits and it is exactly divisible by 15.Our job is to write a program that returns the nearest gapful number to the number we provide as input.For example, for all 2-digit numbers, it would be 100. For 103, it would be ... Read More

170 Views
We are given a main string and a substring, our job is to create a function shedString() that takes in these two arguments and returns a version of the main string which is free of the substring.For example −shedString('12/23/2020', '/');should return a string −'12232020'Let’s now write the code for this function −Exampleconst shedString = (string, separator) => { //we split the string and make it free of separator const separatedArray = string.split(separator); //we join the separatedArray with empty string const separatedString = separatedArray.join(""); return separatedString; } const str = shedString('12/23/2020', '/'); console.log(str);OutputThe output of this ... Read More