AmitDiwan has Published 10740 Articles

Expressing numbers in expanded form - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:32:51

862 Views

Suppose we are given a number 124 and are required to write a function that takes this number as input and returns its expanded form as a string.The expanded form of 124 is −'100+20+4'ExampleFollowing is the code −const num = 125; const expandedForm = num => {    const numStr ... Read More

Replacing every nth instance of characters in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:31:16

1K+ Views

We are required to write a JavaScript function that takes in a string as the first argument, a number, say n, as the second argument and a character, say c, as the third argument. The function should replace the nth appearance of any character with the character provided as the ... Read More

Finding the element larger than all elements on right - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:28:58

194 Views

We are required to write a JavaScript function that takes in an array of numbers and returns a subarray that contains all the element from the original array that are larger than all the elements on their right.ExampleFollowing is the code −const arr = [12, 45, 6, 4, 23, 23, ... Read More

Check for Valid hex code - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:27:29

746 Views

A string can be considered as a valid hex code if it contains no characters other than the 0-9 and a-f alphabetsFor example −'3423ad' is a valid hex code '4234es' is an invalid hex codeWe are required to write a JavaScript function that takes in a string and checks whether ... Read More

Finding persistence of number in JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:25:50

391 Views

We are required to write a JavaScript function that takes in an positive integer and returns its additive persistenceThe additive persistence of an integer, say n, is the number of times we have to replace the number with the sum of its digits until the number becomes a single digit ... Read More

Can array form consecutive sequence - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:24:28

250 Views

We are required to write a JavaScript function that takes in an array of numbers and checks if the elements of the array can be rearranged to form a sequence of numbers or not.For example −If the array is −const arr = [3, 1, 4, 2, 5];Then the output should ... Read More

Checking smooth sentences in JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:23:17

294 Views

We are required to write a JavaScript function that checks whether a sentence is smooth or not. A sentence is smooth when the first letter of each word in the sentence is same as the last letter of its preceding word.ExampleFollowing is the code −const str = 'this stringt tries ... Read More

Strictly increasing or decreasing array - JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:21:57

453 Views

In Mathematics, a strictly increasing function is that function in which the value to be plotted always increase. Similarly, a strictly decreasing function is that function in which the value to be plotted always decrease.We are required to write a JavaScript function that takes in an array of numbers and ... Read More

Determining rightness of a triangle – JavaScript

AmitDiwan

AmitDiwan

Updated on 16-Sep-2020 10:20:47

1K+ Views

We are required to write a JavaScript function that takes in three numbers say a, b and c representing the length of three sides of a triangle. The function should return true if those three sides represent a right-angle triangle, false otherwise.Right angle triangleA triangle is a right-angle triangle if ... Read More

JavaScript - Find the smallest n digit number or greater

AmitDiwan

AmitDiwan

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

414 Views

We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n digit number which is a multiple of all the elements specified in the array. If ... Read More

Advertisements