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
Web Development Articles
Page 427 of 801
How to get the maximum count of repeated letters in a string? JavaScript
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 MoreFetch Second minimum element from an array without sorting JavaScript
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 MoreHow to create a weight converter with HTML and JavaScript?
Creating a weight converter with HTML and JavaScript involves building a simple form that takes weight input in one unit and converts it to another unit in real-time. This tutorial demonstrates how to create a kilogram to gram converter. HTML Structure The HTML provides the basic structure with an input field for kilograms and a display area for the converted grams: body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } input, span{ ...
Read MoreHow to create a temperature converter with HTML and JavaScript?
To create a temperature converter with HTML and JavaScript, you need to combine form elements with JavaScript functions to perform real-time temperature conversions. Complete Temperature Converter Example body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; } .converter-container { background: #f8f9fa; border-radius: ...
Read MoreGet n numbers from array starting from given point JavaScript
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 MoreHow to create a length converter with HTML and JavaScript?
To create a length converter with HTML and JavaScript, you'll need to combine HTML form elements with JavaScript functions to handle the conversion logic. This tutorial demonstrates building a simple kilometer-to-meter converter. HTML Structure The converter uses an input field for kilometers and displays the converted meters value. The oninput and onchange events trigger the conversion function automatically as you type. Complete Example body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; padding: 20px; ...
Read MoreHow to create a speed converter with HTML and JavaScript?
To create a speed converter with HTML and JavaScript, we'll build a simple web application that converts kilometers per hour to meters per second. This involves HTML for the interface and JavaScript for the conversion logic. HTML Structure The HTML creates the user interface with an input field for entering speed values and a display area for the converted result: body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; padding: 20px; ...
Read MoreAmong id, name, xpath and css, which locator should be used?
When selecting locators for web automation, the choice depends on element uniqueness, performance requirements, and traversal needs. Here's a comprehensive guide to choosing the right locator strategy. Locator Priority Order The recommended priority order for locator selection: Priority Locator Reason 1 id Fastest, most reliable if unique 2 name Fast, good for form elements 3 CSS Selector Fast, flexible, good performance 4 XPath Most flexible but slower When to Use Each Locator ID Locator Use when elements have unique IDs. This is the ...
Read MoreHow to identify the nth sub element using xpath?
We can identify the nth sub element using xpath in the following ways: By adding square brackets with index. By using position() method in xpath. Method 1: Using Square Brackets with Index The most common approach is to add square brackets with the desired index number after the element selector: // Select the 2nd div element //div[2] // Select the 3rd li element inside ul //ul/li[3] // Select the first input with type='text' //input[@type='text'][1] Method 2: Using position() Function The position() function provides another way to target elements ...
Read MoreHow to compare two arrays to see how many same elements they have in JavaScript?
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