AmitDiwan has Published 10744 Articles

Constructing a string based on character matrix and number array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 08:16:16

201 Views

ProblemWe are required to write a JavaScript function that takes in an n * n matrix of string characters and an array of integers (positive and unique).Our function should construct a string of those characters whose 1-based index is present in the array of numbers.Character Matrix −[    [‘a’, ‘b’, ... Read More

Returning a range or a number that specifies the square root of a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 08:12:09

169 Views

ProblemWe are required to write a JavaScript function that takes in an integer n and returns either −an integer k if n is a square number, such that k * k == n ora range (k, k+1), such that k * k < n and n < (k+1) * (k+1).ExampleFollowing ... Read More

Returning a decimal that have 1s in its binary form only at indices specified by array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 08:10:39

103 Views

ProblemWe are required to write a JavaScript function that takes in an array of unique non-negative integers. Our function should return a 32-bit integer such that the integer, in its binary representation, has 1 at only those indexes (counted from right) which are in the sequence.ExampleFollowing is the code − Live ... Read More

Finding the 1-based index score of a lowercase alpha string in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 08:07:12

175 Views

ProblemWe are required to write a JavaScript function that takes in a lowercase alphabet string. The index of ‘a’ in alphabets is 1, of ‘b’ is 2 ‘c’ is 3 … of ‘z’ is 26.Our function should sum all the index of the string characters and return the result.ExampleFollowing is ... Read More

Finding the only even or the only odd number in a string of space separated numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 08:04:48

430 Views

ProblemWe are required to write a JavaScript function that takes in a string that contains numbers separated by spaces.The string either contains all odd numbers and only one even number or all even numbers and only one odd number. Our function should return that one different number from the string.ExampleFollowing ... Read More

Return the nearest greater integer of the decimal number it is being called on in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 08:01:59

255 Views

ProblemWe are required to write a JavaScript function that lives in the Math class of JavaScript.Our function should return the nearest greater integer of the decimal number it is being called on.If the number is already an integer, we should return it as it is.ExampleFollowing is the code − Live Democonst ... Read More

All right triangles with specified perimeter in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 07:56:27

135 Views

ProblemWe are required to write a JavaScript function that takes in a number that specifies the perimeter for a triangle. Our function should return an array of all the triangle side triplets whose perimeter is same as specified by the input.ExampleFollowing is the code − Live Democonst perimeter = 120; const ... Read More

Reducing array elements to all odds in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 07:53:59

154 Views

ProblemWe are required to write a JavaScript function that takes in an array. Our function should change the array numbers like this −If the number is odd, leave it changed.If the number is even, subtract 1 from it.And we should return the new array.ExampleFollowing is the code − Live Democonst arr ... Read More

Validating a string with numbers present in it in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 07:48:45

167 Views

ProblemWe are required to write a JavaScript function that takes in a string str. Our function should validate the alphabets in the string based on the numbers before them.We need to split the string by the numbers, and then compare the numbers with the number of characters in the following ... Read More

Realtime moving average of an array of numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 07:45:35

1K+ Views

ProblemWe are required to write a JavaScript function that takes in an array. Our function should construct a new array that stores the moving average of the elements of the input array. For instance −[1, 2, 3, 4, 5] → [1, 1.5, 3, 5, 7.5]First element is the average of ... Read More

Advertisements