
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

352 Views
We have an array of Numbers that are arranged in pure random order. Our job is to write a function that takes in one such array of Numbers and returns the difference of greatest and smallest numbers present in it, but without sorting the array.Therefore, let's write the code for this function −We will use the Array.prototype.reduce() function to pick the smallest and greatest numbers from the array and later will return their difference. The code for this function will be −Exampleconst arr = [23, 65, 67, 23, 2, 6, 87, 23, 45, 65, 3, 234, 3]; const findDifference = ... Read More

396 Views
We have an array of Number/String literals that contains some repeated entries. Our job is to write a function that takes in a positive integer Number n and returns a subarray of all the elements that makes appearance more than or equal to the number n specified by the only argument.Therefore, let's write the code for this function −We will use a Map() to keep count of the frequency of elements and later return the elements that exceed the specified count. The code for this will be −Exampleconst arr = [34, 6, 34, 8, 54, 7, 87, 23, 34, 6, ... Read More

156 Views
Suppose we have an object like this −const obj = { "name": "Vivek Sharma", "occupation": "Software Engineer", "age": 23, "contacts": [{ "name": "Mukul Sharma", "occupation": "Software Engineer", "age": 31, }, { "name": "Jay Sharma", "occupation": "Software Engineer", "age": 27, }, { "name": "Rajan Sharma", "occupation": "Software Engineer", "age": 32, }] };Here it is nested up to only one level, but the nesting can be deeper as ... Read More

243 Views
Suppose we have an array of numbers like this −const arr = [3, 6, 7, 3, 1, 4, 4, 3, 6, 7];This array in the example contains 10 elements, so the index of last element happens to be 9. We are required to write a function that takes in one such array and returns the reverse index multiplied sum of the elements.Like in this example, it would be something like −(9*3)+(8*6)+(7*7)+(6*3)+.... until the end of the array.Therefore, let's write the code for this function −Exampleconst arr = [3, 6, 7, 3, 1, 4, 4, 3, 6, 7]; const reverseMultiSum = ... Read More

353 Views
Normally, the factorial of a positive integer n is the product of all positive integers less than or equal to n. For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.We instead make a clumsy factorial: using the integers in decreasing order, we swap out the multiply operations for a fixed rotation of operations: multiply (*), divide (/), add (+) and subtract (-) in this order.For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * ... Read More

363 Views
We have to write a function maximumDifference() that takes in a positive number n and returns the difference between the maximum number and the minimum number that can be formed out of the number n.For example −If the number n is 203, The maximum number that can be formed from its digits will be 320The minimum number that can be formed from its digits will be 23 (placing the zero at one’s place)And the difference will be −320-23 = 297Therefore, the output should be 297Let's write the code for this function −Exampleconst digitDifference = num => { const asc ... Read More

199 Views
We are required to write a function that takes in a string of definite characters and the function should return the difference between the count of vowels plus other characters and consonants in the string.For example −If the string is −"HEllo World!!"Then, we have 7 consonants, 3 vowels and 3 other characters here so the output should be −|7 - (3+3)| = 1Hence, the output should be 1Let's write the code for this function −Exampleconst str = 'HEllo World!!'; const findDifference = str => { const creds = str.split("").reduce((acc, val) => { let { v, c ... Read More

754 Views
We are required to write a function, say nearestPalindrome() that takes in a number n and returns a palindromic number that is nearest to the number n.For example −If the input number is 264, then the output should be 262If the input number is 7834, then the output should be 7887Basically, the approach will be, we divide the number into two halves (w.r.t. its length) and return the new number which is just the first half concatenated twice.Exampleconst findNearestPalindrome = num => { const strNum = String(num); const half = strNum.substring(0, Math.floor(strNum.length/2)); const reversed = half.split("").reverse().join(""); ... Read More

382 Views
Let’s say, we have an array of arrays that contains some elements like this −const arr = [3, 5, 7, 2, [4, NaN, null, 4, 8, [3, undefined, 24, null], null, 5, 1], NaN, 45, 2, 1];Our job is to write a recursive function that takes in this nested array and replaces all the fale values inside the array (NaN, undefined and null) with 0.Therefore, let's write the code for this function −Exampleconst arr = [3, 5, 7, 2, [4, NaN, null, 4, 8, [3, undefined, 24, null], null, 5, 1], NaN, 45, 2, 1]; const recursiveSimplify = (arr) => ... Read More

449 Views
We are required to write a function, say reverseSum() that takes in two arrays of Numbers, let’s say first and second and returns a new array that contains, Sum of first element of first array and last element of second array as first element, sum of second element of first array and second last element of second array, and so on.When any of the array runs out of element before the other, we simply push all the remaining elements to the array. Therefore, let's write the code for this function −Exampleconst first = [23, 5, 7, 2, 34, 7, 8]; ... Read More