AmitDiwan has Published 10744 Articles

Ways to sort list of dictionaries by values in Python Using lambda function

AmitDiwan

AmitDiwan

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

1K+ Views

When it is required to sort the list of dictionaries based on values, the lambda function can be used.Below is the demonstration of the same −Example Live Demofrom operator import itemgetter my_list = [{ "name" : "Will", "age" : 56}, ... Read More

Counting divisors of a number using JavaScript

AmitDiwan

AmitDiwan

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

560 Views

ProblemWe are required to write a JavaScript function that takes in a number and returns the count of its divisor.Inputconst num = 30;Outputconst output = 8;Because the divisors are −1, 2, 3, 5, 6, 10, 15, 30ExampleFollowing is the code − Live Democonst num = 30; const countDivisors = (num = ... Read More

Hours and minutes from number of seconds using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:35:56

421 Views

ProblemWe are required to write a JavaScript function that takes in the number of second and return the number of hours and number of minutes contained in those seconds.Inputconst seconds = 3601;Outputconst output = "1 hour(s) and 0 minute(s)";ExampleFollowing is the code − Live Democonst seconds = 3601; const toTime = ... Read More

Validating string with reference to array of words using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:35:01

283 Views

ProblemWe are required to write a JavaScript function that takes in a sequence of valid words and a string. Our function should test if the string is made up by one or more words from the array.Inputconst arr = ['love', 'coding', 'i']; const str = 'ilovecoding';Outputconst output = true;Because the ... Read More

Converting humanYears into catYears and dogYears in JavaScript

AmitDiwan

AmitDiwan

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

316 Views

ProblemWe are required to write a JavaScript function that takes in human age in years and returns respective dogYears and catYears.Inputconst humanYears = 15;Outputconst output = [ 15, 76, 89 ];ExampleFollowing is the code − Live Democonst humanYears = 15; const humanYearsCatYearsDogYears = (humanYears) => {    let catYears = 0;    let dogYears = 0;    for (let i = 1; i

Deep count of elements of an array using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:33:58

2K+ Views

ProblemWe are required to write a JavaScript function that takes in a nested array of element and return the deep count of elements present in the array.Inputconst arr = [1, 2, [3, 4, [5]]];Outputconst output = 7;Because the elements at level 1 are 2, elements at level 2 are 2 ... Read More

Replacing dots with dashes in a string using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:33:05

504 Views

ProblemWe are required to write a JavaScript function that takes in a string and replaces all appearances of dots(.) in it with dashes(-).inputconst str = 'this.is.an.example.string';Outputconst output = 'this-is-an-example-string';All appearances of dots(.) in string str are replaced with dash(-)ExampleFollowing is the code − Live Democonst str = 'this.is.an.example.string'; const replaceDots = ... Read More

Isosceles triangles with nearest perimeter using JavaScript

AmitDiwan

AmitDiwan

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

192 Views

Almost Isosceles TriangleAn Almost Isosceles Integer Triangle is a triangle that all its side lengths are integers and also, two sides are almost equal, being their absolute difference 1 unit of length.ProblemWe are required to write a JavaScript function that takes in a number which specifies the perimeter of a ... Read More

Maximum product of any two adjacent elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:29:43

653 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers.Our function should find the maximum product obtained from multiplying 2 adjacent numbers in the array.ExampleFollowing is the code − Live Democonst arr = [9, 5, 10, 2, 24, -1, -48]; function adjacentElementsProduct(array) {    let maxProduct ... Read More

Finding sum of remaining numbers to reach target average using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:29:21

163 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers and a single number.Our function should find that very number which should be pushed to the array so that its average equals the number specified by the second argument.ExampleFollowing is the code − Live Democonst arr ... Read More

Advertisements