AmitDiwan has Published 10744 Articles

Count number of entries in an object having specific values in multiple keys JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 06:17:46

304 Views

Suppose, we have an array of objects like this −const arr = [    {"goods":"Wheat ", "from":"GHANA", "to":"AUSTRALIA"},    {"goods":"Wheat", "from":"USA", "to":"INDIA"},    {"goods":"Wheat", "from":"SINGAPORE", "to":"MALAYSIA"},    {"goods":"Wheat", "from":"USA", "to":"INDIA"}, ];We are required to write a JavaScript function that takes in one such array. The goal of function is to ... Read More

Converting a comma separated string to separate arrays within an object JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 06:15:45

626 Views

Suppose, we have a string like this −const str = 'dress/cotton/black, dress/leather/red, dress/fabric, houses/restaurant/small, houses/school/big, person/james';We are required to write a JavaScript function that takes in one such string. The function should then prepare an object of arrays like this −const output = {    dress = ["cotton", "leather", "black", ... Read More

JavaScript Bubble sort for objects in an array

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:45:06

559 Views

Suppose, we have a constructor class that creates Shoe objects like this −class Shoe {    constructor(name, price, type) {       this.name = name;       this.price = price;       this.type = type;    } };We are using this class to fill an array with ... Read More

Flatten array to 1 line in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:41:58

228 Views

Suppose, we have a nested array of numbers like this −const arr = [    [ 0, 0, 0, −8.5, 28, 8.5 ],    [ 1, 1, −3, 0, 3, 12 ],    [ 2, 2, −0.5, 0, 0.5, 5.3 ] ];We are required to write a JavaScript function that ... Read More

Flat array of objects to tree in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:40:52

706 Views

Suppose, we have an array of objects like this −const arr = [    { id: '1', name: 'name 1', parentId: null },    { id: '2', name: 'name 2', parentId: null },    { id: '2_1', name: 'name 2_1', parentId: '2' },    { id: '2_2', name: 'name 2_2', ... Read More

JavaScript to Calculate the nth root of a number

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:36:32

187 Views

We are required to write a JavaScript function that calculates the nth root of a number and returns it.ExampleThe code for this will be −const findNthRoot = (m, n) => {    try {       let negate = n % 2 == 1 && m < 0;   ... Read More

Partition N where the count of parts and each part are a power of 2, and part size and count are restricted in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:34:35

141 Views

We are required to write a JavaScript function that takes in a number. The function should divide the number into chunks according to the following rules −The number of chunks should be a power−of−two, Each chunk should also have a power-of-two number of items (where size goes up to a ... Read More

Check how many objects are in the array with the same key in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:33:23

1K+ Views

Suppose, we have an array of objects containing some data about some users like this −const arr = [    {       "name":"aaa",       "id":"2100",       "designation":"developer"    },    {       "name":"bbb",       "id":"8888",       "designation":"team lead" ... Read More

Smallest Common Multiple of an array of numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:32:20

369 Views

Suppose, we have an array of two numbers that specify a range. We are required to write a function that finds the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.The range ... Read More

Regroup JSON array in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Nov-2020 10:31:59

318 Views

Suppose, we have a JSON array of objects like this −const arr = [    {       "id": "03868185",       "month_10": 6,    },    {       "id": "03870584",       "month_6": 2,    },    {       "id": "03870584",   ... Read More

Advertisements