AmitDiwan has Published 10740 Articles

Sorting an array of objects by property values - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:21:20

410 Views

Suppose, we have an array of objects like this −const homes = [    {        "h_id": "3",        "city": "Dallas",        "state": "TX",        "zip": "75201",        "price": "162500"    }, {        "h_id": "4",     ... Read More

Finding the length of a JavaScript object

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:19:54

241 Views

Suppose we have an object like this −const obj = {    name: "Ramesh",    age: 34,    occupation: "HR Manager",    address: "Tilak Nagar, New Delhi",    experience: 13 };We are required to write a JavaScript function on Objects that computes their size (i.e., the number of properties in ... Read More

How do we remove a property from a JavaScript object? - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:18:51

322 Views

Let’s say, we have an object as follows −const myObject = {    "ircEvent": "PRIVMSG",    "method": "newURI",    "regex": "^http://.*" };We are required to illustrate the best way to remove the property regex to end up with new myObject?Following is the solution −const myObject = {    "ircEvent": "PRIVMSG", ... Read More

Validating email and password - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:16:38

2K+ Views

Suppose, we have this dummy array that contains the login info of two of many users of a social networking platform −const array = [{    email: 'usman@gmail.com',    password: '123'  },  {    email: 'ali@gmail.com',    password: '123'  } ];We are required to write a JavaScript function that takes ... Read More

The Zombie Apocalypse case study - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:15:03

284 Views

A nasty zombie virus is spreading out in the digital cities. We work at the digital CDC and our job is to look over the city maps and tell which areas are contaminated by the zombie virus so the digital army would know where to drop the bombs.They are the ... Read More

Filter one array with another array - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:13:02

375 Views

Suppose, we have an array and objects like the following −const main = [    {name: "Karan", age: 34},    {name: "Aayush", age: 24},    {name: "Ameesh", age: 23},    {name: "Joy", age: 33},    {name: "Siddarth", age: 43},    {name: "Nakul", age: 31},    {name: "Anmol", age: 21}, ]; ... Read More

How to insert an element into all positions in an array using recursion - JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:11:02

544 Views

We are required to declare a function, let’s say insertAllPositions, which takes two arguments −an element, x, and an array, arr. Functions must return an array of arrays, with each array corresponding to arr with x inserted in a possible position.That is, if arr is the length N, then the ... Read More

How to return object from an array with highest key values along with name - JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:09:18

723 Views

Suppose, we have an array of objects that contains information about marks of some students in a test −const students = [    { name: 'Andy', total: 40 },    { name: 'Seric', total: 50 },    { name: 'Stephen', total: 85 },    { name: 'David', total: 30 }, ... Read More

How can we make an Array of Objects from n properties of n arrays in JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:07:00

194 Views

Suppose we have two arrays of literals like these −const options = ['A', 'B', 'C', 'D']; const values = [true, false, false, false];We are required to write a JavaScript function that creates and returns a new Array of Objects from these two arrays, like this −const response = [   ... Read More

Return 5 random numbers in range, first number cannot be zero - JavaScript

AmitDiwan

AmitDiwan

Updated on 30-Sep-2020 14:37:35

170 Views

We are required to write a JavaScript function that generates an array of exactly five unique random numbers. The condition is that all the numbers have to be in the range [0, 9] and the first number cannot be 0.ExampleFollowing is the code −const fiveRandoms = () => {   ... Read More

Advertisements