Found 6683 Articles for Javascript

Difference between sum of square and square of sum in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 15:30:13

366 Views

In the given problem statement we have to find the difference between sum of square and square of sum with the help of Javascript functionalities. So we will create two functions to do this task. Understanding the Problem The problem at hand is to calculate the sum of squares and the square of the sum for a given set of numbers in Javascript programming. The sum of squares specifies the sum of the squares of every number in the given set. On the other hand the square of the sum means summing up all the numbers in the ... Read More

Sum of all multiples in JavaScript

AmitDiwan
Updated on 25-Nov-2020 12:09:24

196 Views

We are required to write a JavaScript function that takes in a number, say n, as the first argument, and then any number of arguments following that.The idea is to sum all numbers upto n which are divided by any of the numbers specified by second argument and after.For example −If the function is called like this −sumMultiples(15, 2, 3);Then the output should be −const output = 83;Because the numbers are −2, 3, 4, 6, 8, 9, 10, 12, 14, 15ExampleThe code for this will be −const num = 15; const sumMultiple = (num, ...arr) => {    const dividesAny ... Read More

How to split sentence into blocks of fixed length without breaking words in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:26:09

1K+ Views

In the given problem statement we have to split the given sentence into blocks of fixed length without breaking the words of the sentence. And we have to implement the solution in Javascript. Understanding the Problem The problem at hand is to split the given sentence into blocks of a fixed length without breaking its words. So we will divide the sentence into substrings of a given length and also we will ensure that the words will remain intact in every block. For example suppose we have a sentence as "You are reading this article on ... Read More

Generating desired combinations in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 17:58:01

232 Views

In the given problem statement we have to generate the desired combinations of the given inputs. And program the solution with the help of Javascript programming . Understanding the Problem In this problem, we will be given integers from 1 to 9. Each combination should be a unique collection of numbers. The function should identify all the possible combinations of size m that and these items with size m should have the sum of n. For example if the value of m is 3 and n is 6, then the combination should be [1, 2, 3]. ... Read More

Non-negative set subtraction in JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 12:28:08

289 Views

In the given problem statement we are presented with two arrays which contain integer values. So our aim is to find the non negative set subtraction from the two arrays. And implement the solution in Javascript. We can perform this task using the Set object and forEach method. What are the Set object and forEach method in Javascript ? Set object in Javascript The Set is an object in Javascript which is a built in data Structure introduced in ES6. This allows us to store the unique values of any type. The values can be primitive values or ... Read More

Given an array of integers return positives, whose equivalent negatives present in it in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:07:45

371 Views

In the given problem statement we are presented with an array which contains positive and negative values. So our task is to keep the positive once and filter out the negative numbers from the array. And implement the solution in Javascript. Understanding the Problem We will be given an array of integer numbers and we need to find the positive integers which have their respective negative integers present in the array. For example suppose we have an array of integers like [7, -7, 8, -8, 9, -9], in this array we can see that their is some positive ... Read More

Sum up a number until it becomes 1 digit JavaScript

AmitDiwan
Updated on 25-Nov-2020 12:03:49

148 Views

We are required to write a JavaScript function that takes in a Number as the only input. The function should do one simple thing −keep adding the resultant digits until they converse to a single digit number.For example −const num = 5798;i.e.5 + 7 + 9 + 8 = 29 2 + 9 = 11 1 + 1 = 2Hence, the output should be 2ExampleThe code for this will be −const num = 5798; const sumDigits = (num, sum = 0) => {    if(num){       return sumDigits(Math.floor(num / 10), sum + (num % 10));    };    return sum; }; const repeatSum = (num) => {    if(num > 9){       return repeatSum(sumDigits(num));    };    return num; }; console.log(repeatSum(num));OutputAnd the output in the console will be −2

Sorting an integer without using string methods and without using arrays in JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 16:58:47

560 Views

In the given problem statement, our task is to sort an integer number without the usage of string methods and without usage of arrays with the help of Javascript functionalities. So for solving this task we will use mathematical operations and loops in Javascript. Understanding the Problem The problem says to sort the given integer number without using the string and array method in Javascript. The question arises about sorting the integer that means we have to array its digits in ascending or descending order. For example suppose we have an integer number as 784521, so ... Read More

Number Split into individual digits in JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 12:33:34

1K+ Views

In the given problem statement we are presented with a digit and our task is to split it into individual digits with the help of Javascript. So we can convert the given number into a string and then we can use it in string manipulation techniques to get the desired result. Understanding the Problem In Javascript, it is very common to manipulate numbers at the individual digit level. So this is a common task to split the given number into its constituent digits. And extract it for further process or analysis. Logic for the given Problem ... Read More

Find average of each array within an array in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 15:48:27

482 Views

In the given problem statement we are presented with an array which contains multiple subarrays. So our aim is to compute the average of every individual subarray and store these averages in a new array. And implement the solution in Javascript. Understanding the problem The problem has given an array which contains multiple arrays or nested arrays. Every subarray contains some numerical values. Our task is to compute the average of every subarray and collect these averages into a new array. For example we have arrays like this [[4, 6], [2, 4], [6, 2]] so the average of ... Read More

Advertisements