AmitDiwan has Published 10744 Articles

String to binary in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:12:08

7K+ Views

We are required to write a JavaScript function that takes in a string as the only input. The function should construct and return the binary representation of the input string.For example −If the input string is −const str = 'Hello World';Then the output should be −const output = '1001000 1100101 ... Read More

Get the max n values from an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:59:48

555 Views

We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a number, say n, as the second argument.Our function should then pick the n greatest numbers from the array and return a new array consisting of those numbers.ExampleThe code for ... Read More

Remove all occurrences of a multiple occurring element in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:58:28

812 Views

We are required to write a JavaScript function that takes in an array of literal values.The array might contain some repeating values.Our function should remove all the values from the array that are repeating. We are required to remove all instances of all such elements.ExampleThe code for this will be ... Read More

Combine array of objects in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:58:11

349 Views

Suppose, we have an array of objects that contains data about some students like this −const arr = [{    name: 'A',    idNo: 1,    marks: {       math: 98,       sci: 97,       eng: 89    } }, {    name: 'B', ... Read More

Filter JavaScript array of objects with another array

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:50:49

580 Views

Suppose, we have an array of objects like this −const arr = [    {area: 'NY', name: 'Bla', ads: true},    {area: 'DF', name: 'SFS', ads: false},    {area: 'TT', name: 'SDSD', ads: true},    {area: 'SD', name: 'Engine', ads: false},    {area: 'NSK', name: 'Toyota', ads: false}, ];We are ... Read More

Remove the duplicate value from array with images data in JavaScript

AmitDiwan

AmitDiwan

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

446 Views

Suppose, we have some data regarding some images in an array like this −const arr = [{    'image': "jv2bcutaxrms4i_img.png",    'gallery_image': true }, {    'image': "abs.png",    'gallery_image': true }, {    'image': "acd.png",    'gallery_image': false }, {    'image': "jv2bcutaxrms4i_img.png",    'gallery_image': true }, {   ... Read More

Grouping nested array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:47:13

793 Views

Suppose, we have an array of values like this −const arr = [    {       value1:[1, 2],       value2:[{type:'A'}, {type:'B'}]    },    {       value1:[3, 5],       value2:[{type:'B'}, {type:'B'}]    } ];We are required to write a JavaScript function that ... Read More

JavaScript: create an array of JSON objects from linking two arrays

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:43:43

471 Views

Suppose, we have two arrays like these −const meals = ["breakfast", "lunch", "dinner"]; const ingredients = [    ["eggs", "yogurt", "toast"],    ["falafel", "mushrooms", "fries"],    ["pasta", "cheese"] ];We are required to write a JavaScript function that takes in two such arrays and maps the subarrays in the second array ... Read More

Combining two arrays in JavaScript

AmitDiwan

AmitDiwan

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

247 Views

We are required to write a JavaScript function that takes in two arrays of the same length.Our function should then combine corresponding elements of the arrays, to form the corresponding subarray of the output array, and then finally return the output array.If the two arrays are −const arr1 = ['a', ... Read More

Remove item from a nested array by indices in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:41:00

1K+ Views

Suppose, we have a nested array of objects like this −const arr = [    { value: 'some value' },    {       array: [          { value: 'some value' },          {             array: [   ... Read More

Advertisements