AmitDiwan has Published 10744 Articles

Finding nth element of an increasing sequence using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:28:04

240 Views

ProblemConsider an increasing sequence which is defined as follows −The number seq(0) = 1 is the first one in seq.For each x in seq, then y = 2 * x + 1 and z = 3 * x + 1 must be in seq too.There are no other numbers in ... Read More

Reversing negative and positive numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:27:34

1K+ Views

ProblemWe are required to write a JavaScript function that takes in a number and returns its reversed number.One thing that we should keep in mind is that numbers should preserve their sign; i.e., a negative number should still be negative when reversed.ExampleFollowing is the code − Live Democonst num = -224; ... Read More

Boolean Gates in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:27:09

1K+ Views

ProblemWe are required to write a JavaScript function that takes in an array of Boolean values and a logical operator.Our function should return a Boolean result based on sequentially applying the operator to the values in the array.ExampleFollowing is the code − Live Democonst array = [true, true, false]; const op ... Read More

Displaying likes on a post wherein array specifies the names of people that liked a particular post using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:26:44

275 Views

ProblemWe are required to write a JavaScript function that takes in an array of names (string). This array specifies the names of people that liked a particular post on some social networking site.If the count of likes are less than or equal to three our function should simply return all ... Read More

Finding the greatest and smallest number in a space separated string of numbers using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:25:08

305 Views

ProblemWe are required to write a JavaScript function that takes in a string that contains numbers separated by spaces.Our function should return a string that contains only the greatest and the smallest number separated by space.Inputconst str = '5 57 23 23 7 2 78 6';Outputconst output = '78 2';Because ... Read More

Returning lengthy words from a string using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:24:04

107 Views

ProblemWe are required to write a JavaScript function that takes in a sentence of words and a number. The function should return an array of all words greater than the length specified by the number.Inputconst str = 'this is an example of a basic sentence'; const num = 4;Outputconst output ... Read More

Numbers obtained during checking divisibility by 7 using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:22:30

626 Views

ProblemWe can check for a number to be divisible by 7 if it is of the form 10a + b and a - 2b is divisible by 7.We continue to do this until a number known to be divisible by 7 is obtained; we can stop when this number has ... Read More

Can all array elements mesh together in JavaScript?

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:16:09

137 Views

ProblemTwo words can mesh together if the ending substring of the first is the starting substring of the second. For instance, robinhood and hoodie can mesh together.We are required to write a JavaScript function that takes in an array of strings. If all the words in the given array mesh ... Read More

Largest index difference with an increasing value in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:12:20

114 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr. Our function should return the largest difference in indexes j - i such that arr[i] {    const { length: len } = arr;    let res = 0;    for(let i = ... Read More

Finding the missing number between two arrays of literals in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:10:00

609 Views

ProblemWe are required to write a JavaScript function that takes in two arrays arr1 and arr2.arr2 is a shuffled duplicate of arr1 with just one element missing.Our function should find and return that one element.ExampleFollowing is the code − Live Democonst arr1 = [6, 1, 3, 6, 8, 2]; const arr2 ... Read More

Advertisements