AmitDiwan has Published 10744 Articles

Filter array of objects whose properties contains a value in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:35:51

911 Views

Suppose, we have an array of objects like this −const arr = [{    name: 'Paul',    country: 'Canada', }, {    name: 'Lea',    country: 'Italy', }, {    name: 'John',    country: 'Italy', }, ];We are required to devise a way to filter an array of objects depending ... Read More

Remove duplicates and map an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:32:37

600 Views

Suppose, we have an array of objects like this −const arr = [    {id:123, value:"value1", name:"Name1"},    {id:124, value:"value2", name:"Name1"},    {id:125, value:"value3", name:"Name2"},    {id:126, value:"value4", name:"Name2"} ];Note that some of the "name" property in objects within the array are duplicate.We are required to write a JavaScript function ... Read More

How to group an array of objects by key in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:31:17

1K+ Views

Suppose, we have an array of objects containing data about some cars like this −const arr = [    {       'make': 'audi',       'model': 'r8',       'year': '2012'    }, {       'make': 'audi',       'model': 'rs5',     ... Read More

Finding day of week from date (day, month, year) in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:28:11

702 Views

We are required to write a JavaScript function that takes in three argument, namely:day, month and year. Based on these three inputs, our function should find the day of the week on that date.For example: If the inputs are −day = 15, month = 8, year = 1993OutputThen the output ... Read More

Finding the power of a string from a string with repeated letters in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:25:20

531 Views

The power of the string is the maximum length of a non−empty substring that contains only one unique character.We are required to write a JavaScript function that takes in a string and returns its power.For example −const str = "abbcccddddeeeeedcba"Then the output should be 5, because the substring "eeeee" is ... Read More

Checking for straight lines in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:24:19

482 Views

We are required to write a JavaScript function that takes in an array of arrays. Each subarray will contain exactly two items, representing the x and y coordinates respectively.Our function should check whether or not the coordinates specified by these subarrays form a straight line.For example −[[4, 5], [5, 6]] ... Read More

Converting numbers to base-7 representation in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:23:03

732 Views

Like the base−2 representation (binary), where we repeatedly divide the base 10 (decimal) numbers by 2, in the base 7 system we will repeatedly divide the number by 7 to find the binary representation.We are required to write a JavaScript function that takes in any number and finds its base ... Read More

Iterate through Object keys and manipulate the key values in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:19:56

260 Views

Suppose, we have an array of objects like this −const arr = [    {       col1: ["a", "b"],       col2: ["c", "d"]    },    {       col1: ["e", "f"],       col2: ["g", "h"]    } ];We are required to write ... Read More

Function to check two strings and return common words in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:17:17

809 Views

We are required to write a JavaScript function that takes in two strings as arguments. The function should then check the two strings for common characters and prepare a new string of those characters.Lastly, the function should return that string.The code for this will be −Exampleconst str1 = "IloveLinux"; const ... Read More

Filter an array containing objects based on another array containing objects in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 10:36:43

13K+ Views

Suppose we have two arrays of objects like these −const arr1 = [{id:'1', name:'A'}, {id:'2', name:'B'}, {id:'3', name:'C'}, {id:'4', name:'D'}]; const arr2 = [{id:'1', name:'A', state:'healthy'}, {id:'3', name:'C', state:'healthy'}];We are required to write a JavaScript function that takes in two such arrays. Our function should return a new filtered version ... Read More

Advertisements