Found 6683 Articles for Javascript

Checking if a number is some power of the other JavaScript

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

174 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

1K+ 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

363 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

1K+ 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

911 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

305 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

328 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

561 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

Finding longest substring between two same characters JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 12:25:47

392 Views

In this problem statement, our task is to find the longest substring between two same characters with the help of Javascript functionalities. This task can be done with the help of map function to keep track of the two same characters. Logic for the given problem The problem stated that we have to find the longest substring between two same characters in the given string. For example if we have a string like 'abcdefa', there are two same characters 'a' that have 5 characters called 'bcdef', so this will be called longest substring. For implementing the above given problem, ... Read More

Sorting array of Number by increasing frequency JavaScript

AmitDiwan
Updated on 25-Nov-2020 05:14:30

1K+ Views

We are required to write a JavaScript function that takes in an array of numbers that might contain some repeating numbers.The function should sort the array such that the elements that are repeated for the least number of times appears first followed by the elements with increasing frequency.For example −If the input array is −const arr = [1, 1, 2, 2, 2, 3];Then the sorted array should be −const output = [3, 1, 1, 2, 2, 2];Exampleconst arr = [1, 1, 2, 2, 2, 3]; const frequencySort = (arr = []) => {    let map = {};    for ... Read More

Advertisements