AmitDiwan has Published 10744 Articles

Finding sum of every nth element of array in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 08:39:59

1K+ Views

We are required to write a JavaScript function that takes in an array of numbers and returns the cumulative sum of every number present at the index that is a multiple of n from the array.ExampleThe code for this will be −const arr = [5, 3, 5, 6, 12, 5, ... Read More

Excluding extreme elements from average calculation in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:21:22

205 Views

We are required to write a JavaScript function that takes in an array of Number. Then the function should return the average of its elements excluding the smallest and largest Number.ExampleThe code for this will be −const arr = [5, 3, 5, 6, 12, 5, 65, 3, 2]; const findExcludedAverage ... Read More

Equality of corresponding elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:19:50

180 Views

We are required to write a JavaScript function that takes in two arrays of literals. The function should check the corresponding elements of the array. The function should return true if all the corresponding elements of the array are equal otherwise it should return false.ExampleThe code for this will be ... Read More

Splitting a string into parts in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:18:15

360 Views

We are required to write a JavaScript function that takes in a string and a number n (such that n exactly divides the length of string) and we need to return an array of string of length n containing n equal parts of the string.ExampleThe code for this will be ... Read More

Find the second most frequent element in array JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:16:41

687 Views

We are required to write a JavaScript function that takes in a string and returns the character from the string that appears for the second most number of times.ExampleThe code for this will be −const arr = [5, 2, 6, 7, 54, 3, 2, 2, 5, 6, 7, 5, 3, ... Read More

Product of numbers present in a nested array in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:14:52

251 Views

We are required to write a JavaScript function that takes in an array of nested arrays of Numbers and some falsy values (including 0) and some strings as well and the function should return the product of number values present in the nested array. If the array contains some 0s, ... Read More

Number of times a string appears in another JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:07:16

229 Views

We are required to write a JavaScript function that takes in two strings and returns the count of the number of times the str1 appears in the str2.ExampleThe code for this will be −const main = 'This is the is main is string'; const sub = 'is'; const countAppearances = ... Read More

Finding deviations in two Number arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:05:15

116 Views

We are required to write a JavaScript function that takes in Number arrays and returns the element from arrays that are not common to both.For example, if the two arrays are −const arr1 = [2, 4, 2, 4, 6, 4, 3]; const arr2 = [4, 2, 5, 12, 4, 1, ... Read More

Special type of numbers (pronic) in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 08:03:13

143 Views

We are required to write a JavaScript function that takes in a number and returns true if it is a Pronic number otherwise returns false.A Pronic number is a number which is the product of two consecutive integers, that is, a number of the form −n(n + 1)ExampleThe code for ... Read More

Changing positivity/negativity of Numbers in a list in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:58:14

61 Views

We are required to write a JavaScript function that takes in an array of positive as well as negative Numbers and changes the positive numbers to corresponding negative numbers and the negative numbers to corresponding positive numbers in place.ExampleThe code for this will be −const arr = [12, 5, 3, ... Read More

Advertisements