AmitDiwan has Published 10744 Articles

Calculating excluded average - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:08:52

142 Views

Suppose we have an array of objects like this −const arr = [    {val: 56, canUse: true},    {val: 16, canUse: true},    {val: 45, canUse: true},    {val: 76, canUse: false},    {val: 45, canUse: true},    {val: 23, canUse: false},    {val: 23, canUse: false},    {val: ... Read More

Finding all the n digit numbers that have sum of even and odd positioned digits divisible by given numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:07:12

335 Views

We are required to write a JavaScript function that takes in three numbers. Let's say the three numbers are a, b and n.Our job is to find all the n-digit numbers whose sum of digits at even positions and odd positions are divisible by a and b respectively. And we ... Read More

Finding the rotation of an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:58:56

181 Views

We are required to write a JavaScript function that takes in an array and a number n.Our function should rotate the array by n elements, i.e., take n elements from the front and put them to the end.The only condition here is that we have to do this without using ... Read More

Thrice sum of elements of array - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:53:52

207 Views

We are required to write a JavaScript function that takes in an array of Numbers and returns a new array with elements as sum of three consecutive elements from the original array.For example, if the input array is −const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, ... Read More

Does this array contain any majority element - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:52:54

123 Views

Given an array of Numbers, any element of the array will be a majority element if that element appears more than array length's 1/2 times in the array.For example −If the length of array is 7, Then if there's any element in the array that appears for at least 4 ... Read More

Are array of numbers equal - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:51:19

144 Views

We are required to write a JavaScript function that takes in two arrays of Numbers, say first and second and checks for their equality.The arrays will be considered equal if −They contain the same elements and in the same order.The product of all the elements of the first array and ... Read More

Check whether a string ends with some other string - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:50:14

154 Views

We are required to write a JavaScript function that takes in two strings say, str1 and str2. The function should determine whether or not str1 ends with str2. Our function should return a boolean on this basis.Here’s our 1st string −const str1 = 'this is just an example';Here’s our 2nd ... Read More

Finding special type of numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:49:05

186 Views

In the decimal number system, all the real numbers can be divided into two groups −Rational NumbersIrrational NumbersFor the scope of this problem we will only discuss the rational numbers, All those numbers which can be written in the p/q (where q !== 0) form are called rational numbers.Like 14, ... Read More

JavaScript: Finding nearest prime number greater or equal to sum of digits - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:47:58

166 Views

We are required to write a JavaScript function that takes in a number, finds the sum of its digits and returns a prime number that is just greater than or equal to the sum.ExampleFollowing is the code −const num = 56563; const digitSum = (num, sum = 0) => { ... Read More

Converting a JavaScript object to an array of values - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 13:46:12

257 Views

We are required to create an array out of a JavaScript object, containing the values of all of the object's properties. For example, given this object −{    "firstName": "John",    "lastName": "Smith",    "isAlive": "true",    "age": "25" } We have to produce this array −const myarray = ['John', 'Smith', ... Read More

Advertisements