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
Javascript Articles
Page 345 of 534
Find the longest sub array of consecutive numbers with a while loop in JavaScript
We are required to write a function with a while-statement that determines the length of the largest consecutive subarray in an array of positive integers. For instance, if we have an array like [6, 7, 8, 6, 12, 1, 2, 3, 4], the longest consecutive sequence is [1, 2, 3, 4] with length 4. Problem Understanding Let's look at some examples to understand the problem better: Input: [6, 7, 8, 6, 12, 1, 2, 3, 4] Consecutive sequence: [1, 2, 3, 4] Output: 4 Input: [5, 6, 1, 8, 9, 7] Consecutive ...
Read MoreHow to offset an outline and draw it beyond the border edge with JavaScript?
To offset an outline in JavaScript, use the outlineOffset property. This CSS property allows you to draw the outline beyond the border edge, creating space between the element's border and its outline. Syntax element.style.outlineOffset = "value"; The value can be specified in pixels (px), ems (em), or other CSS length units. Positive values move the outline away from the border, while negative values move it inward. Example #box { ...
Read MoreSimplifying nested array JavaScript
Let's say, we have an array of arrays that contains some elements like this − const arr = [3, 5, 7, 2, [4, NaN, null, 4, 8, [3, undefined, 24, null], null, 5, 1], NaN, 45, 2, 1]; Our job is to write a recursive function that takes in this nested array and replaces all the falsy values inside the array (NaN, undefined and null) with 0. Understanding Falsy Values In JavaScript, falsy values include: null undefined NaN ...
Read MoreHow to set the width of the outline around an element with JavaScript?
To set the outline width, use the outlineWidth property. The outline appears outside the border and doesn't affect the element's layout. You can set it using pixel values, keywords, or other CSS units. Syntax element.style.outlineWidth = value; Parameters The outlineWidth property accepts the following values: Pixel values: "1px", "5px", "10px" Keywords: "thin", "medium", "thick" Other units: "1em", "2rem", "0.5cm" Example #box { width: 450px; ...
Read MoreNearest palindrome in JavaScript
We are required to write a function that takes in a number n and returns a palindromic number that is nearest to the number n. A palindrome reads the same forwards and backwards. For example: If the input number is 264, then the output should be 262 If the input number is 7834, then the output should be 7887 Approach The approach divides the number into two halves based on its length and creates a palindrome by mirroring the first half. For odd-length numbers, the middle digit remains unchanged. Example const ...
Read MoreHow to set the style of the outline around an element with JavaScript?
To set the outline style around an element in JavaScript, use the outlineStyle property. This property controls the visual appearance of the outline, which is drawn outside the border and doesn't affect the element's dimensions. Syntax element.style.outlineStyle = "value"; Common Outline Style Values The outlineStyle property accepts these values: solid - A solid line dotted - A series of dots dashed - A series of dashes double - Two solid lines groove - A 3D grooved outline ...
Read MoreVowel, other characters and consonant difference in a string JavaScript
We are required to write a function that takes in a string of definite characters and the function should return the difference between the count of vowels plus other characters and consonants in the string. Problem Explanation For example, if the string is: "HEllo World!!" Then, we have 7 consonants, 3 vowels and 3 other characters here so the output should be: |7 - (3+3)| = 1 Hence, the output should be 1 Example const str = 'HEllo World!!'; const findDifference = str => { const creds ...
Read MoreWhat to do with content that renders outside the element box with JavaScript?
When content exceeds an element's dimensions, it can overflow outside the visible area. JavaScript provides several ways to handle this using the overflow property, which controls how overflowing content is displayed. Understanding Overflow Values The overflow property accepts several values: visible - Default behavior, content flows outside the box hidden - Clips content that overflows scroll - Always shows scrollbars auto - Shows scrollbars only when needed Example: Dynamic Overflow Control Here's a complete example demonstrating how to manage overflow with JavaScript: ...
Read MoreReturn the difference between the maximum & minimum number formed out of the number n in JavaScript
We have to write a function that takes a positive number n and returns the difference between the maximum number and the minimum number that can be formed from its digits. For example, if the number n is 203: The maximum number that can be formed from its digits will be 320 The minimum number that can be formed from its digits will be 23 (placing the zero at one's place) And the difference will be: 320 - 23 = 297 Therefore, the output should ...
Read MoreWhat should be done with the left/ right edges of the content on overflow with JavaScript?
When content overflows horizontally in a container, the overflowX property controls how the left and right edges are handled. This property allows you to add horizontal scrolling, hide overflow, or make it visible. Syntax element.style.overflowX = "value"; Common overflowX Values Value Description Use Case scroll Always shows horizontal scrollbar ...
Read More