 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Web Development Articles - Page 237 of 1049
 
 
			
			706 Views
Parity BitA parity bit, or check bit, is a bit added to a string of bits to ensure that the total number of 1-bits in the string is even or odd.ProblemWe are required to write a JavaScript function that takes in two parameters, one being the wanted parity (always 'even' or 'odd'), and the other being the binary representation of the number we want to check.The task of our function is to return an integer (0 or 1), which is the parity bit we need to add to the binary representation so that the parity of the resulting string is ... Read More
 
 
			
			196 Views
ProblemWe are required to write a JavaScript function that takes in a string that contains binary strings of length 3 all separated by spaces.Our function should sort the numbers in ascending order but only order the even numbers and leave all odd numbers in their place.ExampleFollowing is the code − Live Democonst str = '101 111 100 001 010'; const sortEvenIncreasing = (str = '') => { const sorter = (a, b) => { const findInteger = bi => parseInt(bi, 2); if(findInteger(a) % 2 === 1 || findInteger(b) % 2 === 1){ return 0; }; return findInteger(a) - findInteger(b); }; const res = str .split(' ') .sort(sorter) .join(' '); return res; }; console.log(sortEvenIncreasing(str));Output101 111 100 001 010
 
 
			
			2K+ Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers sorted in increasing order.Our function should calculate the variance for the array of numbers. Variance of a set of numbers is calculated on the basis of their mean.$Mean (M) = ( \sum_{i=0}^{n-1} arr[i])$ / nAnd variance (V) = $(\sum_{i=0}^{n-1} (arr[i] - M)^2)$ / nExampleFollowing is the code − Live Democonst arr = [4, 6, 7, 8, 9, 10, 10]; const findVariance = (arr = []) => { if(!arr.length){ return 0; }; const sum = arr.reduce((acc, val) => acc + val); ... Read More
 
 
			
			542 Views
ProblemWe are required to write a JavaScript function that takes in a mathematical expression as a string and return its result as a number.We need to support the following mathematical operators −Division / (as floating-point division)Addition +Subtraction -Multiplication *Operators are always evaluated from left-to-right, and * and / must be evaluated before + and -.ExampleFollowing is the code − Live Democonst exp = '6 - 4'; const findResult = (exp = '') => { const digits = '0123456789.'; const operators = ['+', '-', '*', '/', 'negate']; const legend = { '+': { pred: 2, func: ... Read More
311 Views
In the realm of JavaScript programming, effectively managing the occurrences of elements within an array is of paramount importance. Specifically, the ability to delete instances of an element if it surpasses a certain threshold, denoted by the variable "n, " can greatly enhance the efficiency and accuracy of data manipulation tasks. By harnessing the power of JavaScript, developers can employ a robust approach to selectively remove redundant element occurrences from arrays. In this article, we will embark on a comprehensive exploration of the step-by-step process for deleting occurrences of an element if it occurs more than "n" times using JavaScript, ... Read More
 
 
			
			166 Views
ProblemWe are required to write a JavaScript function that takes in an array of n strings. And each string in the array consists of exactly n characters.Our function should first sort the array in alphabetical order. And then return the string formed by the characters present at the principal diagonal starting from the top left corner.ExampleFollowing is the code − Live Democonst arr = [ 'star', 'abcd', 'calm', 'need' ]; const sortPickDiagonal = () => { const copy = arr.slice(); copy.sort(); let res = ''; for(let i = 0; i < copy.length; i++){ ... Read More
 
 
			
			295 Views
ProblemWe are required to write a JavaScript function that takes in three arrays of numbers. Our function should return the sum of all those numbers that are common in all three arrays.ExampleFollowing is the code − Live Democonst arr1 = [4, 4, 5, 8, 3]; const arr2 = [7, 3, 7, 4, 1]; const arr3 = [11, 0, 7, 3, 4]; const sumCommon = (arr1 = [], arr2 = [], arr3 = []) => { let sum = 0; for(let i = 0; i < arr1.length; i++){ const el = arr1[i]; const ind2 = arr2.indexOf(el); const ind3 = arr3.indexOf(el); if(ind2 !== -1 && ind3 !== -1){ arr2.splice(ind2, 1); arr3.splice(ind3, 1); sum += el; }; }; return sum; }; console.log(sumCommon(arr1, arr2, arr3));Output7
 
 
			
			386 Views
ProblemWe are required to write a JavaScript function that takes in a number n and bound number b.Our function should find the largest integer num, such that −num is divisible by divisornum is less than or equal to boundnum is greater than 0.ExampleFollowing is the code − Live Democonst n = 14; const b = 400; const biggestDivisible = (n, b) => { let max = 0; for(let j = n; j max){ max = j; }; } return max; }; console.log(biggestDivisible(n, b));Output392
 
 
			
			322 Views
ProblemWe are required to write a JavaScript function that takes in a 2-D array of numbers. Our function should pick the smallest number from each row of the 2-D array and then finally return the sum of those smallest numbers.ExampleFollowing is the code − Live Democonst arr = [ [2, 5, 1, 6], [6, 8, 5, 8], [3, 6, 7, 5], [9, 11, 13, 12] ]; const sumSmallest = (arr = []) => { const findSmallest = array => array.reduce((acc, val) => { return Math.min(acc, val); }, Infinity) let sum = 0; arr.forEach(sub => { sum += findSmallest(sub); }); return sum; }; console.log(sumSmallest(arr));Output18
 
 
			
			478 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers. The array is sorted in ascending / increasing order and only one element in the array is out of order.Our function should find and return that element.ExampleFollowing is the code −const arr = [1, 2, 3, 4, 17, 5, 6, 7, 8]; const findWrongNumber = (arr = []) > { for(let i = 0; i < arr.length - 1; i++){ const el = arr[i]; if(el - arr[i + 1] < 0 && arr[i + 1] - arr[i + 2] > 0){ return arr[i + 1]; } }; }; console.log(findWrongNumber(arr));Output17