Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by AmitDiwan
Page 370 of 840
Get the size of the screen, current web page and browser window in JavaScript
In JavaScript, you can get different dimensions of the screen, browser window, and web page content using various window properties. This is useful for responsive design, creating dynamic layouts, and adjusting content based on available space. We will explore three main categories: Get the Inner Width and Height (viewport size) Get the Outer Width and Height (entire browser window) Get Screen Dimensions Understanding Different Size Properties Property ...
Read MoreKeeping only alphanumerals in a JavaScript string in JavaScript
We are required to write a JavaScript function that takes in a string that might contain some special characters. The function should return a new string that has all special characters replaced with their corresponding ASCII value, keeping only alphanumeric characters and spaces in their original form. Therefore, let's write the code for this function: Example The code for this will be: const str = 'Th!s !s @ str!ng th@t cont@!ns some special characters!!'; const specialToASCII = str => { let res = ''; for(let i ...
Read MoreHow to find and return the longest repeating series of numbers in array with JavaScript
We are required to write a JavaScript function that takes in an array of Numbers that may contain some repeating elements. The function should return the length of the longest repeating number sequence from the array. For example − If the input array is − const arr = [2, 1, 1, 2, 3, 3, 2, 2, 2, 1]; Then the output should be 3 because the number 2 is repeated 3 times consecutively in the array (and that's the highest number). Using Array.reduce() Method The reduce() method can be used to group ...
Read MoreSubarray sum with at least two elements in JavaScript
We need to write a JavaScript function that takes an array of integers and a target value, then checks whether there exists a continuous subarray of size at least 2 that sums up to a multiple of the target value. Problem Statement Given an array of integers and a target value k, return true if there exists a continuous subarray of size at least 2 that sums up to n*k (where n is any integer), otherwise return false. For example: Input: arr = [23, 2, 6, 4, 7], target = 6 Output: true ...
Read MoreGrouping nested array in JavaScript
Suppose, we have an array of values like this − const arr = [ { value1:[1, 2], value2:[{type:'A'}, {type:'B'}] }, { value1:[3, 5], value2:[{type:'B'}, {type:'B'}] } ]; We are required to write a JavaScript function that takes in one such array. Our function should then prepare an array ...
Read MoreFinding the longest substring uncommon in array in JavaScript
In JavaScript, finding the longest uncommon subsequence in an array involves identifying the longest string that appears only once or doesn't exist as a subsequence in other strings. Understanding Subsequence A subsequence is a sequence derived from another sequence by deleting some characters without changing the order of remaining elements. Any string is a subsequence of itself, and an empty string is a subsequence of any string. Problem Definition We need to find the length of the longest uncommon subsequence among an array of strings. An uncommon subsequence is a subsequence of one string that is ...
Read MoreEncrypting censored words using JavaScript
This tutorial demonstrates how to encrypt or mask censored words in JavaScript by applying specific transformation rules to convert regular text into a masked format. Problem We need to write a JavaScript function that takes in a string and converts it according to the following rules: All words should be in uppercase Every word should end with '!!!!' Any letter 'a' or 'A' should become '@' Any other vowel (E, I, O, U) should become '*' Solution Here's the implementation of the word masking function: const str = 'ban censored words'; ...
Read MoreSum of all the non-repeating elements of an array JavaScript
To find the sum of non-repeating elements in an array, we need to identify elements that appear exactly once and add them together. Problem Statement Given an array of numbers, we want to calculate the sum of all elements that appear only once in the array. const arr = [14, 54, 23, 14, 24, 33, 44, 54, 77, 87, 77, 14]; console.log("Input array:", arr); Input array: [14, 54, 23, 14, 24, 33, 44, 54, 77, 87, 77, 14] In this array, the non-repeating elements are: 23, 24, 33, 44, 87. Their ...
Read MoreIf the element repeats, remove all its instances from array in JavaScript
When working with arrays in JavaScript, sometimes you need to remove all instances of elements that appear more than once, keeping only elements that appear exactly once. This is different from typical deduplication where you keep one instance of each duplicate. For example, if the input is: const arr = [763, 55, 43, 22, 32, 43, 763, 43]; console.log("Original array:", arr); Original array: [ 763, 55, 43, 22, 32, 43, 763, 43 ] The output should be: [ 55, 22, 32 ] Notice that 763 and 43 are ...
Read MoreJavaScript function that takes a multidimensional and a single array, and finds matches of the single array in the multi-d array
We need to write a JavaScript function that takes a multidimensional array (array of arrays) as the first argument and a single array as the second argument. The function should find common elements between each subarray and the single array, returning a new array containing only the matching elements from each subarray. Problem Understanding For each subarray in the multidimensional array, we want to find elements that also exist in the single array. The result preserves the structure but only includes common elements. For example, if we have: const arr1 = [ ...
Read More