AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 370 of 840

Get the size of the screen, current web page and browser window in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

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 More

Keeping only alphanumerals in a JavaScript string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 183 Views

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 More

How to find and return the longest repeating series of numbers in array with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 646 Views

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 More

Subarray sum with at least two elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 248 Views

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 More

Grouping nested array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 867 Views

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 More

Finding the longest substring uncommon in array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 253 Views

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 More

Encrypting censored words using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 324 Views

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 More

Sum of all the non-repeating elements of an array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 508 Views

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 More

If the element repeats, remove all its instances from array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 154 Views

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 More

JavaScript function that takes a multidimensional and a single array, and finds matches of the single array in the multi-d array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 206 Views

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
Showing 3691–3700 of 8,392 articles
« Prev 1 368 369 370 371 372 840 Next »
Advertisements