AmitDiwan has Published 10744 Articles

Equal partition of an array of numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:28:56

275 Views

We are required to write a function that returns true if we can partition an array into one element and the rest, such that this one element is equal to the product of all other elements excluding itself, false otherwise.For example: If the array is −const arr = [1, 56, ... Read More

Find distinct elements - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:27:48

141 Views

We are required to write a JavaScript function that takes in an array of literals, such that some array elements are repeated. We are required to return an array that contains that appear only once (not repeated).For example: If the array is:>const arr = [9, 5, 6, 8, 7, 7, ... Read More

Filtering out primes from an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:26:21

2K+ Views

We are required to write a JavaScript function that takes in the following array of numbers, const arr = [34, 56, 3, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34];and returns a new filtered array that does not contain any prime number.ExampleFollowing is the code −const arr = ... Read More

Resolving or rejecting promises accordingly - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:25:16

102 Views

We are required to write a JavaScript function that imitates a network request, for that we can use the JavaScript setTimeout() function, that executes a task after a given time interval.Our function should return a promise that resolves when the request takes place successfully, otherwise it rejectsExampleFollowing is the code ... Read More

Frequency distribution of elements - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:22:50

1K+ Views

We are required to write a JavaScript function that contains the following string −const str = 'This string will be used to calculate frequency distribution';We need to return an object that represents the frequency distribution of various elements present in the array.ExampleFollowing is the code −const str = 'This string ... Read More

Finding mistakes in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:21:38

482 Views

We are required to write a JavaScript function that takes in two strings. The first string is some mistyped string and the second string is the correct version of this sting. We can assume that the two strings we are getting as argument will always have the same length.We have ... Read More

Implementing Priority Sort in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:20:26

2K+ Views

We are required to write a JavaScript function that takes in two arrays of numbers, second being smaller in size than the first.Our function should be a sorted version of the first array (say in increasing order) but put all the elements that are common in both arrays to the ... Read More

Converting a proper fraction to mixed fraction - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:19:27

478 Views

Proper FractionA proper fraction is the one that exists in the p/q form (both p and q being natural numbers)Mixed FractionSuppose we divide the numerator of a fraction (say a) with its denominator (say b), to get quotient q and remainder r.The mixed fraction form for fraction (a/b) will be ... Read More

Reversing the prime length words - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:18:30

198 Views

We are required to write a JavaScript function that takes in a string that contains strings joined by whitespaces. Our function should create a new string that has all the words from the original string and the words whose length is a prime number reversed i.e. words with length 2, ... Read More

Temperature converter using JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:16:58

578 Views

We are required to write a JavaScript function that takes in a string representing a temperature either in Celsius or in Fahrenheit.Like this −"23F", "43C", "23F"We are required to write a JavaScript function that takes in this string and converts the temperature from Celsius to Fahrenheit and Fahrenheit to Celsius.ExampleFollowing ... Read More

Advertisements