Javascript Articles

Page 344 of 534

How to get the maximum count of repeated letters in a string? JavaScript

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

We have a string that contains some repeated letters like this: const a = "fdsfjngjkdsfhhhhhhhhhhhfsdfsd"; Our job is to write a function that returns the count of maximum consecutive same letters in a streak. Like in the above string the letter 'h' appears for 11 times in a row consecutively, so our function should return 11 for this string. This problem is a good candidate for the sliding window algorithm, where a stable window contains consecutive identical letters and one that contains different elements is unstable. The window adjusts by moving the start pointer when different characters ...

Read More

How to set the maximum width of an element with JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

The maxWidth property in JavaScript allows you to set the maximum width of an element dynamically. This property controls how wide an element can grow, which is particularly useful for responsive layouts and content that needs width constraints. Syntax element.style.maxWidth = "value"; The value can be specified in pixels (px), percentages (%), em, rem, or other valid CSS units. Example: Setting Maximum Width #box { ...

Read More

Fetch Second minimum element from an array without sorting JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 543 Views

We have an array of Numbers, and we are required to write a function that returns the second smallest value from the array. For example − if the array is − const arr = [67, 87, 56, 8, 56, 78, 54, 67, 98, 56, 54]; Then the output should be the following − 54 because 54 is the smallest value after 8 Method 1: Using indexOf and splice This approach finds the minimum element, removes it from a copy of the array, then finds the minimum of the remaining ...

Read More

How to set the minimum height of an element with JavaScript?

Kumar Varma
Kumar Varma
Updated on 15-Mar-2026 748 Views

Use the minHeight property in JavaScript to set the minimum height of an element. This property ensures that an element maintains at least the specified height, even if its content is smaller. Syntax element.style.minHeight = "value"; The value can be specified in pixels (px), percentages (%), em units, or other CSS length units. Example: Setting Minimum Height #box { width: 300px; ...

Read More

Get n numbers from array starting from given point JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 323 Views

We need to create a custom Array method that extracts n elements from an array starting at a given index, moving in a specified direction (left or right). When we reach array boundaries, the function wraps around to continue from the other end. Problem Requirements The function should take three parameters: n - number of elements to extract m - starting index (must be ≤ array.length - 1) direction - either 'left' or 'right' For example, if we have [0, 1, 2, 3, 4, 5, 6, 7] and call get(4, 6, 'right'), it should return ...

Read More

How to set the minimum width of an element with JavaScript?

Rishi Raj
Rishi Raj
Updated on 15-Mar-2026 1K+ Views

Use the minWidth property in JavaScript to set the minimum width of an element. This property ensures an element maintains at least the specified width, even when its content or CSS would make it smaller. Syntax element.style.minWidth = "value"; The value can be specified in pixels (px), percentages (%), or other CSS units like em, rem, or vw. Example: Setting Minimum Width #box { width: 50%; ...

Read More

How to compare two arrays to see how many same elements they have in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 456 Views

Let's say, we have two arrays, one contains the correct answer strings of some questions and one contains the answers attempted by a candidate, but somehow the arrays got shuffled and now they don't have answers in corresponding order. But we can be sure that no two questions had the same answers. Our job now is to write a function that takes these two arrays, checks them for common elements and finds all the common elements between them and then calculates the marks percentage of the candidate based on the count of common answers. Example const ...

Read More

How to set the opacity level for an element with JavaScript?

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 930 Views

Use the opacity property in JavaScript to set the opacity level for any element. The opacity value ranges from 0 (completely transparent) to 1 (completely opaque). Syntax element.style.opacity = "value"; Where value is a number between 0 and 1: 0 - Completely transparent (invisible) 0.5 - 50% transparent 1 - Completely opaque (default) Example: Basic Opacity Control #box { width: 450px; ...

Read More

From an array of arrays, return an array where each item is the sum of all the items in the corresponding subarray in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 357 Views

Given an array of arrays, each of which contains a set of numbers. We have to write a function that returns an array where each item is the sum of all the items in the corresponding subarray. For example, if we have nested arrays with numbers, we want to calculate the sum of each inner array and return those sums as a new array. Example Input and Expected Output If the input array is: const numbers = [ [1, 2, 3, 4], [5, 6, 7], [8, ...

Read More

How to set all the outline properties in one declaration with JavaScript?

Monica Mona
Monica Mona
Updated on 15-Mar-2026 214 Views

To set outline properties, use the outline property. It allows you to set the color, style, and width of the outline in one declaration with JavaScript. Syntax The outline property accepts up to three values in any order: element.style.outline = "width style color"; Parameters outline-width: thin, medium, thick, or specific value (px, em, etc.) outline-style: none, solid, dotted, dashed, double, groove, ridge, inset, outset outline-color: color name, hex code, rgb(), or rgba() Example Click the button to apply an outline to the orange box: ...

Read More
Showing 3431–3440 of 5,340 articles
« Prev 1 342 343 344 345 346 534 Next »
Advertisements