
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
An Array is known as collection of similar data elements which are stored at contiguous memory locations. Array is such a simple data structure where we can access each data element in the array with the help index numbers, which starts from 0. The following is the basic declaration of array in JavaScript − const mobiles = ["SAMSUNG", "ONEPLUS", "APPLE"]; Sum of two consecutive elements of an array We are required to write a JavaScript function that takes in an array of Numbers and returns a new array with elements as sum of two consecutive elements from ... Read More

187 Views
We are required to write a JavaScript function that takes in a string representing a number. The function returns true if the number is pandigital, false otherwise.A pandigital number is a number that contains all digits (0-9) at least once.Therefore, let’s write the code for this function −ExampleThe code for this will be −const numStr1 = '47458892414'; const numStr2 = '53657687691428890'; const isPandigital = numStr => { let legend = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; for(let i = 0; i < numStr.length; i++){ if(!legend.includes(numStr[i])){ continue; ... Read More

149 Views
We are required to write a JavaScript function that takes in two strings; creates and returns a new string with first 2 words of first string, next two words of second string, then first, then second and so on.For example: If the strings are −const str1 = 'Hello world'; const str2 = 'How are you btw';Then the output should be −const output = 'HeHollw o arwoe rlyodu btw';Therefore, let’s write the code for this function −ExampleThe code for this will be −const str1 = 'Hello world'; const str2 = 'How are you btw'; const twiceJoin = (str1 = '', str2 ... Read More

283 Views
We are required to write a JavaScript function that takes in a string and returns the character which makes second most appearances in the string.Therefore, let’s write the code for this function −ExampleThe code for this will be −const str = 'Hello world, I have never seen such a beautiful weather in the world'; const secondFrequent = str => { const map = {}; for(let i = 0; i < str.length; i++){ map[str[i]] = (map[str[i]] || 0) + 1; }; const freqArr = Object.keys(map).map(el => [el, map[el]]); freqArr.sort((a, b) => b[1] - ... Read More

145 Views
We are required to write a JavaScript function that takes in a string and starts mapping its characters from 0.And every time, the function encounters a unique (non-duplicate) character it should increase the mapping count by 1 otherwise it should map the same number for duplicate characters.For example: If the string is −const str = 'heeeyyyy';Then the output should be −const output = [0, 1, 1, 1, 2, 2, 2, 2];Therefore, let’s write the code for this function −ExampleThe code for this will be −const str = 'heeeyyyy'; const mapString = str => { const res = []; ... Read More

150 Views
We are required to write a JavaScript function that takes in an array of numbers and reorders the digit of all the numbers internally in a specific order (let’s say in ascending order for the sake of this problem).For example: If the array is −const arr = [543, 65, 343, 75, 567, 878, 87];Then the output should be −const output = [345, 56, 334, 57, 567, 788, 78];Therefore, let’s write the code for this function −ExampleThe code for this will be −const arr = [543, 65, 343, 75, 567, 878, 87]; const ascendNumber = num => { const numArr ... Read More

222 Views
We are required to write a JavaScript function that takes in a string and returns the count of redundant characters in the string.For example: If the string is −const str = 'abcde'Then the output should be 0.If the string is −const str = 'aaacbfsc';Then the output should be 3.ExampleThe code for this will be −const str = 'aaacbfsc'; const countRedundant = str => { let count = 0; for(let i = 0; i < str.length; i++){ if(i === str.lastIndexOf(str[i])){ continue; }; count++; }; return count; }; console.log(countRedundant(str));OutputThe output in the console will be −3

533 Views
We are required to write a JavaScript function that takes in an array of strings, ordered by ascending length.The function should return true if, for each pair of consecutive strings, the second string can be formed from the first by adding a single letter either at the beginning or end.For example: If the array is given by −const arr = ["c", "ca", "can", "acan", "acane", "dacane"];Then our function should return trueTherefore, let’s write the code for this function.ExampleThe code for this will be −const arr = ["c", "ca", "can", "acan", "acane", "dacane"]; const isProgressive = arr => { for(let ... Read More

245 Views
We are required to write a JavaScript function that takes in a string and returns a new string with the last vowel of each word removed.For example: If the string is −const str = 'This is an example string';Then the output should be −const output = 'Ths s n exampl strng';Therefore, let’s write the code for this function −ExampleThe code for this will be −const str = 'This is an example string'; const removeLast = word => { const lastIndex = el => word.lastIndexOf(el); const ind = Math.max(lastIndex('a'), lastIndex('e'), lastIndex('i'), lastIndex('o'), lastIndex('u')); return word.substr(0, ind) + word.substr(ind+1, ... Read More

141 Views
We are required to write a JavaScript function that takes in two numbers and returns their difference but without using the (-) sign.Therefore, let’s write the code for this function −ExampleThe code for this will be −const num1 = 56; const num = 78; const subtractWithoutMinus = (num1, num2) => { if(num2 === 0){ return num1; }; return subtractWithoutMinus(num1 ^ num2, (~num1 & num2)