
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 8591 Articles for Front End Technology

235 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a number, num, (num { const res = []; let sum = 0, right = 0, left = 0; for(; right < num; right++){ sum += arr[right]; }; res.push(sum); while(right < arr.length){ sum -= arr[left]; sum += arr[right]; right++; left++; res.push(sum); }; return res; }; console.log(accumulateArray(arr, num));OutputFollowing is the console output−[3, 5, 7, 9, 11]

174 Views
ProblemWe are required to write a JavaScript function that takes in two arrays of literals, arr1 and arr2, as the first and the second argument.Our function should find out the common element in arr1 and arr2 with the least list index sum. If there is a choice tie between answers, we should output all of them with no order requirement.For example, if the input to the function is− Live Democonst arr1 = ['a', 'b', 'c', 'd']; const arr2 = ['d', 'a', 'c'];Then the output should be −const output = ['a'];Output ExplanationSince 'd' and 'a' are common in both the arrays the ... Read More

190 Views
ProblemWe are required to write a JavaScript function that takes in a string number as the only argument.Our function should return the input number with the second half of digits changed to 0.In cases where the number has an odd number of digits, the middle digit onwards should be changed to 0.For example −938473 → 938000ExampleFollowing is the code − Live Democonst num = '938473'; const convertHalf = (num = '') => { let i = num.toString(); let j = Math.floor(i.length / 2); if (j * 2 === i.length) { return parseInt(i.slice(0, j) + '0'.repeat(j)); ... Read More

164 Views
ProblemWe are required to write a JavaScript function that takes in a number n. Our function is required to return the maximum value by rearranging its digits.ExampleFollowing is the code −const num = 124; const rotateToMax = n => { n = n .toString() .split('') .map(el => +el); n.sort((a, b) => return b - a; }); return n .join(''); }; console.log(rotateToMax(num));Output421

351 Views
ProblemWe are required to write a JavaScript function that takes in an array of integers. Our function should sum the differences between consecutive pairs in the array in descending order.For example − If the array is −[6, 2, 15]Then the output should be −(15 - 6) + (6 - 2) = 13ExampleFollowing is the code − Live Democonst arr = [6, 2, 15]; const sumDifference = (arr = []) => { const descArr = arr.sort((a, b) => b - a); if (descArr.length

206 Views
ProblemWe are required to write a JavaScript function that takes in a number and checks each digit if it is divisible by the digit on its left and returns an array of booleans.The booleans should always start with false because there is no digit before the first one.ExampleFollowing is the code − Live Democonst num = 73312; const divisibleByPrevious = (n = 1) => { const str = n.toString(); const arr = [false]; for(let i = 1; i < str.length; ++i){ if(str[i] % str[i-1] === 0){ arr.push(true); }else{ arr.push(false); }; }; return arr; }; console.log(divisibleByPrevious(num));Output[ false, false, true, false, true ]

137 Views
ProblemWe are required to write a JavaScript function that takes in an array of positive integers. Our function should map this array to an array of string integers.The array should contain the number we should add/subtract to the first element to achieve the corresponding element.For example[4, 3, 6, 2]should return −['+0', '-1', '+2', '-2']ExampleFollowing is the code − Live Democonst arr = [4, 3, 6, 2]; const buildRelative = (arr = []) => { const res = []; let num = ''; for(let i of arr){ if(i - arr[0] >= 0){ ... Read More
145 Views
In the realm of JavaScript programming, the ability to construct an array of smaller elements than their corresponding counterparts from an input array holds immense significance. This intriguing technique allows developers to manipulate and transform data, opening doors to innovative solutions and efficient algorithms. By harnessing the power of JavaScript's array manipulation capabilities, developers can generate new arrays with elements that are scaled down or reduced based on the values of the original array. In this article, we delve into the art of constructing an array of smaller elements than the corresponding elements from an input array, exploring the underlying ... Read More

206 Views
ProblemWe are required to write a JavaScript function that takes in a lowercase English alphabet character. Our function should return the character’s 1-based index in the alphabets.ExampleFollowing is the code − Live Democonst char = 'j'; const findCharIndex = (char = '') => { const legend = ' abcdefghijklmnopqrstuvwxyz'; if(!char || !legend.includes(char) || char.length !== 1){ return -1; }; return legend.indexOf(char); }; console.log(findCharIndex(char));Output10