AmitDiwan has Published 10744 Articles

Convert JavaScript array iteration result into a single line text string

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 14:16:44

297 Views

Let’s say, we have a string and an array −const textString = 'Convert javascript array iteration result into a single line text string. Happy searching!'; const keywords = ['integer', 'javascript', 'dry', 'Happy', 'exam'];We have to write a function that maps the array to a string containing only true and false ... Read More

Inverse operation in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 14:13:52

910 Views

Let’s say, we have to write a function that takes in a binary string (consisting of only 0 and 1) and returns its inverse, all 0s replaced by 1 and 1s replaced by 0.Let’s write the code for this function −Exampleconst num = '1101'; const n = '11010111'; const inverseBinary ... Read More

Merge objects in array with similar key JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 14:10:14

2K+ Views

Let’s say, we have the following array of objects −const arr = [    {id: 1, h1: 'Daily tests'},    {id: 2, h1: 'Details'},    {id: 1, h2: 'Daily classes'},    {id: 3, h2: 'Results'},    {id: 2, h3: 'Admissions'},    {id: 1, h4: 'Students'},    {id: 2, h5: 'Alumni'}, ... Read More

Order an array of words based on another array of words JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 14:07:19

343 Views

Let’s say, we have the following array of objects sorted according to its id property −const unordered = [{    id: 1,    string: 'sometimes' }, {    id: 2,    string: 'be' }, {    id: 3,    string: 'can' }, {    id: 4,    string: 'life' }, ... Read More

How to Sort object of objects by its key value JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 13:55:27

632 Views

Let’s say, we have an object with keys as string literals and their values as objects as well like this −const companies = {    'landwaves ltd': {employees: 1200, worth: '1.2m', CEO: 'Rajiv Bansal'},    'colin & co': {employees: 200, worth: '0.2m', CEO: 'Sukesh Maheshwari'},    'motilal biscuits': {employees: 975, ... Read More

How to combine 2 arrays into 1 object in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 13:51:33

750 Views

Let’s say, we have two arrays of equal lengths and are required to write a function that maps the two arrays into an object. The corresponding elements of the first array becomes the corresponding keys of the object and the elements of the second array become the value.We will reduce ... Read More

Make numbers in array relative to 0 – 100 in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 13:49:40

236 Views

Let’s say, we have an array that contains some numbers, our job is to write a function that takes in the array and maps all the values relative to 0 to 100. Means that the greatest number should get replaced by 100, the smallest by 100 and all others should ... Read More

Positive integer square array JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 13:46:49

332 Views

Let’s say, we have an array that contains some numbers, positive, negative, decimals and integers. We have to write a function that takes in an array and returns an array of square of all the positive integers from the original array.Let’s write the code for this function −Exampleconst arr = ... Read More

How to splice duplicate item in array JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 13:42:16

666 Views

We have an array of Number / String literals that contain some duplicate values, we have to remove these values from the array without creating a new array or storing the duplicate values anywhere else.We will use the Array.prototype.splice() method to remove entries inplace, and we will take help of ... Read More

Sum from array values with similar key in JavaScript

AmitDiwan

AmitDiwan

Updated on 21-Aug-2020 13:34:47

537 Views

Let’s say, here is an array that contains some data about the stocks sold and purchased by some company over a period of time.const transactions = [    ['AAPL', 'buy', 100],    ['WMT', 'sell', 75],    ['MCD', 'buy', 125],    ['GOOG', 'sell', 10],    ['AAPL', 'buy', 100],    ['AAPL', 'sell', ... Read More

Advertisements