AmitDiwan has Published 10744 Articles

How to find the biggest number in an array around undefined elements? - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:57:35

232 Views

We are required to write a JavaScript function that takes in an array that contains some numbers, some strings and some falsy values.Our function should return the biggest Number from the array.For example −If the input array is the following with some undefined values −const arr = [23, 'hello', undefined, ... Read More

How to select the middle of an array?  - JavaScript

AmitDiwan

AmitDiwan

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

596 Views

We are required to write a JavaScript function that takes in an array of Numbers.The function should return the middlemost element of the array.For example −If the array is −const arr = [1, 2, 3, 4, 5, 6, 7];Then the output should be 4ExampleFollowing is the code −const arr = ... Read More

Convert array into array of subarrays - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:52:32

987 Views

We are required to write a JavaScript function that takes in an array of literals and returns a new array that have elements of the original array chunked into subarrays of length exactly 2.Now if the length of original array is not exactly divisible by 2, then the last subarray ... Read More

Merge two objects in JavaScript ignoring undefined values

AmitDiwan

AmitDiwan

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

2K+ Views

Suppose, we have two objects, say A and B like these −const A = { activity: 'purchased', count: undefined, time: '09:05:33' }; const B = { activity: 'purchased', count: '51', time: undefined }; We are required to write a JavaScript function that merges these two objects, keeping in mind if any ... Read More

Sort an array to have specific items first in the array - JavaScript

AmitDiwan

AmitDiwan

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

2K+ Views

Suppose, we have an array of objects like this −const arr = [    {flag: true, other: 1},    {flag: true, other: 2},    {flag: false, other: 3},    {flag: true, other: 4},    {flag: true, other: 5},    {flag: true, other: 6},    {flag: false, other: 7} ];We are ... Read More

Sort array of objects by string property value - JavaScript

AmitDiwan

AmitDiwan

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

315 Views

Suppose, we have an array of Objects like this −const arr = [    { first_name: 'Lazslo', last_name: 'Jamf'     },    { first_name: 'Pig',    last_name: 'Bodine'   },    { first_name: 'Pirate', last_name: 'Prentice' } ];We are required to write a JavaScript function that takes in one ... Read More

Grouping array nested value while comparing 2 objects - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 10:45:30

406 Views

Suppose, we have the following JSON object −const input = {    "before": {      "device": [        {          "id": "1234",          "price": "10",          "features": [            {         ... Read More

JavaScript: Balancing parentheses

AmitDiwan

AmitDiwan

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

2K+ Views

Given a string that consists of only two types of characters: "(" and ")". We are required to write a function that takes in one such string and balances the parentheses by inserting either a "(" or a ")" as many times as necessary.The function should then return the minimum ... Read More

Compare and fill arrays - JavaScript

AmitDiwan

AmitDiwan

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

223 Views

We are required to write a function that compares two arrays and creates a third array filling that array with all the elements of the second array and filling null for all those elements that are present in the first array but misses out in the second array.For example −If ... Read More

How to validate if an element in an array is repeated? - JavaScript

AmitDiwan

AmitDiwan

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

295 Views

We are required to write a JavaScript function that takes in two arguments −An Array, say arr, of literals that may contain some repeating elements.A number, say limit.The function should validate that no element of the array is repeated more than limit number of times. If any element is repeated ... Read More

Advertisements