AmitDiwan has Published 10740 Articles

Find the average of all elements of array except the largest and smallest - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:25:35

353 Views

We are required to write a JavaScript function that takes in an array of Number and returns the averages of its elements excluding the smallest and largest Number.Let’s write the code for this function −Following is the code −const arr = [1, 4, 5, 3, 5, 6, 12, 5, 65, ... Read More

Program to test the equality of two arrays - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:21:04

158 Views

We are required to write a JavaScript function that takes in two arrays of literals and checks the corresponding elements of the array and it should return true if all the corresponding elements of the array are equal otherwise it should return false.Let’s write the code for this function −ExampleFollowing ... Read More

Divide a string into n equal parts - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:19:06

662 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). We need to return an array of string of length n containing n equal parts of the string.Let’s write the code for this function ... Read More

Find Second most frequent character in array - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:16:53

614 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.Let’s say the following is our array −const arr = [1, 34, 4, 3, 2, 1, 4, 6, 4, 6, 5, 3, ... Read More

Recursive multiplication in array - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:12:40

407 Views

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

Count appearances of a string in another - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:09:11

142 Views

We are required to write a JavaScript function that takes in two strings and returns the count of the number of times the first string appears in the second stringLet’s say our string is −const main = 'This is the is main is string';We have to find the appearance of ... Read More

Program to find uncommon elements in two arrays - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:07:32

2K+ Views

Let’s say, we have two arrays of numbers −const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34];We are required to write a JavaScript function that takes in two such arrays and returns the element from arrays that are ... Read More

Pronic numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:05:35

267 Views

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

Inverting signs in array - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:03:41

600 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.Let’s write the code for this function −ExampleFollowing is the code −const ... Read More

Finding if three points are collinear - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:01:39

664 Views

Collinear PointsThree or more points that lie on the same straight line are called collinear points.And three points lie on the same if the slope of all three pairs of lines formed by them is equal.Consider, for example, three arbitrary points A, B and C on a 2-D plane, they ... Read More

Advertisements