Javascript Articles

Page 243 of 534

All possible odd length subarrays JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 546 Views

In this problem statement, our task is to find all the possible odd length subarrays with the help of JavaScript functionalities. This task can be done with the help of some built-in functions of JavaScript or we can solve it by multiple for loops. Logic for the Given Problem The problem states that we have to get all the possible odd length subarrays in JavaScript programming language. The meaning of odd length is that the length of the subarrays should be 1, 3, 5, 7, and so on. So our task is to filter the subarrays with odd ...

Read More

Checking for string anagrams JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 419 Views

In this problem statement, our aim is to check for string anagrams with the help of Javascript functionalities. So for solving this problem first we need to understand the problem in simple terms. Understanding the Problem Statement We have given two strings as input and our main aim is to check if the strings are anagrams of each other. If they are anagrams then return true otherwise return false. What are Anagrams? An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all the original letters exactly once. ...

Read More

Checking if a number is some power of the other JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 466 Views

In this problem statement, our objective is to check if a given input number is some power of another number using JavaScript functionalities. Logic for the Problem To determine if a number a is a power of another number b, we can use logarithms. If a = b^n for some integer n, then log_b(a) = n should be an integer. Since JavaScript's Math.log() returns the natural logarithm, we use the change of base formula: log_b(a) = ln(a) / ln(b). If this result is an integer, then a is a power of b. Algorithm Step 1 ...

Read More

Destructively Sum all the digits of a number in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 721 Views

Our main task is to write a function that destructively sums all the digits of a number using JavaScript. This approach modifies the original number during the calculation process by extracting each digit until none remain. Understanding the Problem The goal is to create a function that calculates the sum of all digits in a given number. The term "destructive" means the original number is modified during the process as we extract each digit. For example, given the number 123, we need to calculate: 1 + 2 + 3 = 6. Algorithm Step 1 − ...

Read More

Dynamic Programming - Part sum of elements JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 537 Views

In this problem, we calculate the sum of all elements except one element at each step, creating an array of partial sums. We'll implement this using JavaScript array methods and dynamic programming concepts. Problem Statement Given an array of n elements, generate an array containing: The sum of all elements The sum of all elements except the first element The sum of all elements except the second element And so on for each element Algorithm Step 1: Calculate the total sum of all elements in the array. Step 2: Create a result array starting ...

Read More

Fetch Numbers with Even Number of Digits JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 515 Views

In JavaScript, finding numbers with an even count of digits means identifying numbers where the total digit count is divisible by 2. This is different from finding even numbers themselves. Understanding the Problem We need to create a function that takes an array of numbers and returns only those numbers that have an even number of digits. For example, in the array [12, 345, 67, 8910, 11, 9], the numbers 12 (2 digits), 67 (2 digits), and 8910 (4 digits) have even digit counts. Method 1: Using String Length Convert each number to a string and ...

Read More

Finding longest substring between two same characters JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 588 Views

In this problem, we need to find the longest substring between two same characters in a string using JavaScript. We'll use a Map to track character positions and calculate distances between matching characters. Problem Explanation Given a string like 'abcdefa', we have two 'a' characters with 'bcdef' between them (5 characters). This becomes our longest substring between same characters. Algorithm Steps Step 1 − Define function longestSubstring with parameter 'str'. Step 2 − Initialize maxLength = 0 and begin = -1 to track the longest substring. Step 3 − Create a Map called charMap to store ...

Read More

Function to find out palindrome strings JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 256 Views

In this problem statement, our aim is to create a function to find out that the given string is palindrome with the help of Javascript functionalities. So for solving this problem first we need to understand the problem in simple terms. Understanding the Problem Statement We have given a string as an input string and our main aim is to check if the string is a palindrome string or not. If it is palindrome then return true otherwise return false. What is a Palindrome? A palindrome is a string that reads the same forwards and backwards. ...

Read More

Function to reverse a string JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 628 Views

In JavaScript, reversing a string is a common programming task that can be accomplished using various approaches. This tutorial demonstrates how to create a function that reverses any given string by iterating through its characters in reverse order. Understanding the Problem String reversal means rearranging the characters of a string so that the last character becomes first, second-last becomes second, and so on. For example, if we have the string "Hello", the reverse will be "olleH". Algorithm Step 1 − Declare a variable to store the reversed string and initialize it as empty. Step 2 − ...

Read More

Get all substrings of a string in JavaScript recursively

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 3K+ Views

In JavaScript, generating all substrings of a string can be elegantly solved using recursion. A substring is any continuous sequence of characters within a string. For example, the string "abc" has substrings: "a", "b", "c", "ab", "bc", and "abc". Understanding the Problem We need to create a recursive function that generates all possible substrings of a given input string. For the string "xy", the possible substrings are "x", "y", and "xy". The recursive approach systematically explores all starting and ending positions to build each substring. Algorithm Steps Step 1 − Define the main function that accepts ...

Read More
Showing 2421–2430 of 5,340 articles
« Prev 1 241 242 243 244 245 534 Next »
Advertisements