Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 17 of 17

Find number of spaces in a string using JavaScript

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

In JavaScript, counting spaces in a string is a common task that can be accomplished using several built-in methods. This article explores different approaches to find the number of space characters in a string. Problem Overview Given a string with space characters, we need to count how many spaces it contains. For example, the string "Hello world example" contains 2 spaces. const exampleString = "This is an example of counting spaces"; // Expected output: 6 spaces Method 1: Using split() Method The split() method divides a string into an array based on a ...

Read More

Calculating median of an array in JavaScript

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

In this problem statement, our task is to calculate the median of an array with the help of Javascript functionalities. There are several ways that can be used to solve this task. One simple method to calculate median is using the built-in function of Javascript. Understanding the Problem The problem statement is to write a function in Javascript that will help to calculate the median of a given array. The median is the middle value when numbers are arranged in ascending order. For example: Array [1, 2, 3, 4, 5] has median 3 (middle element) Array ...

Read More

How to find distance between items on array JavaScript?

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

In JavaScript, finding the distance between array items means calculating how many positions separate two elements. The distance is measured as the absolute difference between their index positions. Understanding the Problem Array distance represents the number of steps needed to move from one element to another. For example, in the array [1, 2, 3, 4, 5], the distance between elements 2 and 4 is 2 because their indices are 1 and 3 respectively, giving us |3 - 1| = 2. Basic Distance Calculation The simplest approach uses indexOf() to find element positions and calculates the absolute ...

Read More
Showing 161–163 of 163 articles
« Prev 1 13 14 15 16 17 Next »
Advertisements