Javascript Articles - Page 220 of 607

JavaScript Count repeating letter

Nikitasha Shrivastava
Updated on 18-May-2023 14:39:38

3K+ Views

In this problem statement, our target is to count the repeating letter in the given string with the help of Javascript functionalities. So we can solve this problem with the help of loops and some built-in methods of Javascript. Logic for the given problem In the given problem statement we have to design a program to count the repeating letters in the given string. For implementing this task first we will create a blank object for count, array for repeated characters and another object for results. Then we will loop through every character in the string. So for every ... Read More

N consecutive odd numbers JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:05:33

760 Views

In this problem statement, our target is to print the n consecutive odd numbers and implement this problem with the help of Javascript functionalities. So we can solve this problem with the help of loops in Javascript. Logic for the given problem In the given problem statement we have to design a program to generate a given number of consecutive odd numbers starting from 1. It will be done by creating an empty array to store the odd numbers and then using a loop which will run n times to add every odd number to the created array. The loop ... Read More

Checking if a number is some power of the other JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 11:56:48

439 Views

In this problem statement, our objective is to check if a given input number is some power of the other number. And implement this problem with the help of Javascript functionalities. Logic for the given problem The main objective of this problem statement is to determine if a given number is a power of another number. We need to use Javascript to implement this code. To check if a number a is a power of another number b, we can take the logarithm of a with base b using the math.log function and then we can check if the ... Read More

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 14:01:36

2K+ Views

Our work in this problem statement is to find the pair of adjacent elements that has the largest product and return the product if we have given an array. And we have to implement this problem with the help of Javascript functionalities. Logic for the given problem In the given problem statement we have to calculate the product of the largest elements in the array and show the resultant output to the console. So we will implement this problem with two methods: first is by using the infinity and second without using infinity. Infinity is a global object. The ... Read More

Dynamic Programming - Part sum of elements JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 12:07:59

513 Views

In this problem statement, our task is to calculate the sum of all the elements of the array and remove one element at every step and show the resultant array of sum of all the possible subarrays. And implement this problem with the help of Javascript functionalities. Logic for the given problem The given problem states that we have to calculate the sum of every element except one element at every step. To solve the given problem we will define an array as input and return the output as an array of sums of elements by deducting one element ... Read More

Find possible numbers in array that can sum to a target value JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 12:22:49

2K+ Views

In this problem statement, we are required to find all the possible numbers in an array that can sum to a given target value 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 stated that we have to get the possible numbers in an array which can give the exact value as target value by summing them up with the help of Javascript functionalities. As we have to find out the numbers ... Read More

Finding number of spaces in a string JavaScript

AmitDiwan
Updated on 25-Nov-2020 05:23:36

1K+ Views

We are required to write a JavaScript function that takes in a string containing spaces. The function should simply count the number of spaces present in that string.For example −If the input string is −const str = 'this is a string';Then the output should be −const output = 4;Exampleconst str = 'this is a string'; const countSpaces = (str = '') => {    let count = 0;    for(let i = 0;    i < str.length; i++){       const el = str[i];       if(el !== ' '){          continue; };          count++; };       return count; }; console.log(countSpaces(str));OutputThis will produce the following output −4

All possible odd length subarrays JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 11:28:52

519 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 stated that we have to get all the possible odd length of the subarrays in Javascript programming language. The meaning of add length is that the length of the subarrays should be 1, 3, 5, 7, .....end so on. So our task is to filter the length ... Read More

Special arrays in JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 16:02:38

554 Views

In this problem statement, our task is to show working of some special arrays and their characteristics in Javascript programming. In Javascript a special array can be dependent on the given context. The special arrays can refer to different types of arrays depending on the condition and context. There are some interpretations possible: Typed arrays, Sparse arrays and Array with string keys. What is the Typed Array? In Javascript there are many built-in methods available for typed array objects. These arrays are special in the context that they represent the array of a specific type of data in it. ... Read More

Average of array excluding min max JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 11:31:23

866 Views

In this problem statement, our task is to find the average of the array excluding minimum and maximum values from the array with the help of Javascript functionalities. This task can be done by excluding the minimum and maximum values and calculating the average of the rest of the elements. Logic for the given problem To create the program for this problem we will use the Math function of Javascript to get the minimum and maximum values with the help of min and max keywords. After we are having the values of min and max now we will ... Read More

Advertisements