Found 6683 Articles for Javascript

Partial sum in array of arrays JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 12:59:11

195 Views

In the given problem statement our task is to get the partial sum in an array of arrays with the help of Javascript functionalities. So we will calculate the sum of rows and give the result. Understanding the Problem The problem at hand is to compute the partial sum of an array of arrays. So first understand what an array of arrays is! Array of arrays means each item represents an array itself. For example see the below array of arrays: [ [11, 12, 13], [14, 15, 16], [17, 18, 19] ] The partial sum at ... Read More

Destructively Sum all the digits of a number in JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 12:01:21

465 Views

Our main task is to write the function to destructively sum all the digits of a number with the help of Javascript. So for doing this task we will use a while loop and a function to get the desired output. Understanding the problem statement The problem is to create a function to calculate the sum of all the digits in the given number. Means we have given a number and we have to calculate the sum of all the digits in a destructive manner as the original number is modified during the process. For example let's say we have ... Read More

Finding Number of Days Between Two Dates JavaScript

AmitDiwan
Updated on 25-Nov-2020 07:54:45

170 Views

We are required to write a JavaScript function that takes in two dates in the 'YYYY-MM-DD' format as the first and second argument respectively. The function should then calculate and return the number of days between the two dates.For example −If the input dates are −const str1 = '2020-05-21'; const str2 = '2020-05-25';Then the output should be −const output = 4;Exampleconst str2 = '2020-05-25'; const daysBetweenDates = (str1, str2) => {    const leapYears = (year, month) => {       if (month (year * 365) + leapYears(year, month) + monthDays[month] + d; let p = days(...str1.split('-').map(Number));   ... Read More

Mapping values to keys JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 14:56:16

596 Views

In the given problem statement we have to write a method for mapping values to keys with the help of Javascript. So for doing this task we will use an object literal in Javascript. Understanding the problem statement So we have to find out the value for the given key and for doing this task we can use an object literal. An object is a data structure which can store the data in key-value pairs. So the keys are the identifier of the values. With the help of keys we can access the values. In Javascript there are several methods ... Read More

Return the element that appears for second most number of times in the array JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:41:47

93 Views

In the given problem statement, our task is to return the element that appears for the second most number of times in the array with the help of Javascript. So to solve this problem we will use map function to count the frequency of every element. Understanding the problem statement The given problem is to get the element in the given array which appears for the second most number of times. Suppose we have an array of integer numbers [1, 3, 3, 4, 4, 4] so the function should return 3 as we can see in the array 3 is ... Read More

Maximum difference between a number JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:01:39

147 Views

In this problem statement, our task is to write the function for finding the maximum difference between a number in an array with the usage of Javascript functionalities. So we will use a nested loop to get the difference between two numbers. Understanding the problem statement The above problem statement is saying to find the maximum difference between any two numbers in the given array of integer numbers. In simple terms we have to find the largest possible difference between any two numbers of the array in which the larger number appears after the smaller number. Suppose we have an ... Read More

Fetch Numbers with Even Number of Digits JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 12:15:53

324 Views

In the given problem statement our task is to write the function for fetching the numbers with an even number of digits with the help of Javascript. For solving this task we will use a for loop and push every even number in the array. Understanding the problem statement The problem statement is to write a function which will take an array of numbers as input and return the array for containing only numbers that have an even number of digits. For example if we have an input array is [1 ,2 , 3, 4, 5] the function should return ... Read More

Numbers smaller than the current number JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:30:45

417 Views

In the given problem statement we have to find the smaller numbers than the current number with the help of Javascript. So for doing this task we will be keeping track of the items and decrement the current number by one to get the desired result. Understanding the problem statement The problem statement is asked to write a function which will take an array of integers as input and will return the array of the same length in which every element shows the count of the numbers in the given array which are smaller than the respective item. For example ... Read More

JavaScript Total subarrays with Sum K

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:34:25

316 Views

In this problem statement, our task is to write the function for getting the total subarrays with sum K with the help of Javascript. So for doing this task we will use basic functionality of Javascript. Understanding the problem statement The problem statement is to create a function which will take an array of integers and a target sum K. So after processing the calculation it will return the total number of subarrays in the array with a sum of K. A subarray can be defined as a continuous series of items in the array. For example suppose ... Read More

Split a range of number to a specific number of intervals JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 16:08:39

2K+ Views

In this problem statement, our task is to write the function splitting a range of numbers to a specific number of intervals with the help of Javascript. So for doing this task we will have to give start, end and the intervals. Understanding the problem statement The problem statement is saying to create a function which can split a range of numbers into a specific number of intervals. And the inputs will be starting and ending numbers of the range and the desired number of intervals. So the outcome should be the array of subarrays which shows each interval. These ... Read More

Advertisements