AmitDiwan has Published 10744 Articles

Insert value in the middle of every value inside array JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 09:24:57

358 Views

We have an array of numbers like this −const numbers = [1, 6, 7, 8, 3, 98];We have to convert this array of numbers into an array of objects with each object having a key as “value” and its value as a specific value of the array element. Besides this ... Read More

Check if values of two arrays are the same/equal in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 09:10:59

626 Views

We have two arrays of numbers, let’s say −[2, 4, 6, 7, 1] [4, 1, 7, 6, 2]Assume, we have to write a function that returns a boolean based on the fact whether or not they contain the same elements irrespective of their order.For example −[2, 4, 6, 7, 1] ... Read More

Strictly increasing sequence JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 09:09:08

1K+ Views

Given a sequence of integers as an array, we have to determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.For example −For sequence = [1, 3, 2, 1], the output should be function(sequence) = false. There is no ... Read More

Filter away object in array with null values JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 09:07:24

2K+ Views

Let’s say, we have an array of objects about some employees of a company. But the array contains some bad data i.e., key pointing to empty strings or false values. Our job is to write a function that takes in the array and away the objects that have null or ... Read More

Create a Calculator function in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 08:59:06

817 Views

We have to write a function, say calculator() that takes in one of the four characters (+, - , *, / ) as the first argument and any number of Number literals after that. Our job is to perform the operation specified as the first argument over those numbers and ... Read More

Solution for array reverse algorithm problem JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 08:56:01

215 Views

We have a requirement that we have to write a function to reverse an array but without changing the index of a special character presents in an array, like below example −If ‘#’ is that special character then, the following array, [18, -4, '#', 0, 8, '#', 5]should return −[5, ... Read More

Return the largest array between arrays JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 08:54:23

348 Views

We have an array of arrays that contains some numbers, we have to write a function that returns the takes in that array and returns the index of the subarray that has the maximum sum. If more than one subarray has the same maximum sum, we have to return the ... Read More

How to sum all elements in a nested array? JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 06:11:08

2K+ Views

Let’s say, we are supposed to write a function that takes in a nested array of Numbers and returns the sum of all the numbers. We are required to do this without using the Array.prototype.flat() method.Let’s write the code for this function −Exampleconst arr = [    5,    7, ... Read More

How to compare two arrays in JavaScript and make a new one of true and false? JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 06:09:43

478 Views

We have 2 arrays in JavaScript and we want to compare one with the other to see if the elements of master array exists in keys array, and then make one new array of the same length that of the master array but containing only true and false (being true ... Read More

Converting string to MORSE code in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Aug-2020 06:08:04

3K+ Views

What is Morse code?Morse code is a method used in telecommunications to encode text characters as standardized sequences of two different signal durations, called dots and dashes.To have a function that converts a particular string to Morse code, we will need an object that maps all the characters (English alphabets) ... Read More

Advertisements