AmitDiwan has Published 10744 Articles

Determining isomorphic strings JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 07:08:50

784 Views

Two strings (str1 and str2) are isomorphic if the characters in str1 can be replaced to get str2.For example −const str1 = 'abcde'; const str2 = 'eabdc';These two are an example of isomorphic stringsWe are required to write a JavaScript function that in two strings. The function should determine whether ... Read More

Counting prime numbers from 2 upto the number n JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 07:07:59

412 Views

We are required to write a JavaScript function that takes in a number, say n, as the first and the only argument.The function should then return the count of all the prime numbers from 2 upto the number n.For example −For n = 10, the output should be: 4 (2, ... Read More

Finding trailing zeros of a factorial JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 07:06:56

422 Views

Given an integer n, we have to write a function that returns the number of trailing zeroes in n!.For example −trailingZeroes(4) = 0 trailingZeroes(5) = 1 because 5! = 120 trailingZeroes(6) = 1Exampleconst num = 17; const findTrailingZeroes = num => {    let cur = 5, total = 0;    while (cur

Calculate average from JSON data based on multiple filters JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 07:05:38

1K+ Views

Suppose, we have an array of objects like this −const arr = [    { "SupplierName" : "John", "Category " : "A", "Points" : 3 },    { "SupplierName" : "John", "Category " : "A", "Points" : 11 },    { "SupplierName" : "John", "Category " : "A", "Points" : ... Read More

Sort array based on min and max date in JavaScript?

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 07:03:07

604 Views

Suppose, we have an array of string dates like this −const arr = [    "2017-01-22 00:21:17.0",    "2017-01-27 11:30:23.0",    "2017-01-24 15:53:21.0",    "2017-01-27 11:34:18.0",    "2017-01-26 16:55:48.0",    "2017-01-22 11:57:12.0",    "2017-01-27 11:35:43.0" ];We are required to write a JavaScript function that takes in one such array. The ... Read More

Group a JavaScript Array

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 07:01:10

315 Views

Suppose, we have a JavaScript array like this −const data = [    {       "dataId": "1",       "tableName": "table1",       "column": "firstHeader",       "rows": [          "a", "b", "c"       ]    },    {   ... Read More

How to transform two or more spaces in a string in only one space? JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 06:58:05

298 Views

We have to write a JavaScript program that takes a variable user string through an input in HTML. Then through JavaScript the program should check for more than one consecutive spaces in the string.And the program should replace all such instances of more than one consecutive spaces with only one ... Read More

Sorting only a part of an array JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 06:56:13

855 Views

We are required to write a JavaScript function that takes in an array of strings as the first argument and two numbers as second and third argument respectively.The purpose of our function is to sort the array. But we have to sort only that part of the array that falls ... Read More

Grade book challenge JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 06:55:03

320 Views

We are required to write a function that finds the mean of the three scores passed to it and returns the letter value associated with that grade according to the following table.Exampleconst findGrade = (...scores) => {    const {       length    } = scores;    const ... Read More

How to sort mixed numeric/alphanumeric array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 06:50:10

3K+ Views

Suppose we have an array of alphanumeric strings like this −const arr = ['A1', 'A10', 'A11', 'A12', 'A3A', 'A3B', 'A3', 'A4', 'B10', 'B2', 'F1', '1', '2', 'F3'];We are required to write a JavaScript function that in one such array as one and the only argument.And the function should sort this ... Read More

Advertisements