AmitDiwan has Published 10744 Articles

Greatest element in a Multi-Dimensional Array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 12:04:11

141 Views

We have to write a simple function in JavaScript that takes in an array of Numbers (nested to any level) and return the greatest number present in the array.For example:If the input array is −const arr = [    34, 65, 67,    [       43, 76, 87, ... Read More

Cumulative average of pair of elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 12:00:52

227 Views

We have an array of numbers and are required to write a function that returns an array with the average of the corresponding element and its predecessor.For the first element, as there are no predecessors, so that very element should be returned.Let’s write the code for this function, we will ... Read More

Inserting empty string in place of repeating values in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:58:16

448 Views

We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end.For example: If we find 4 duplicate values we have to remove then all and insert four empty strings at the end.Therefore, let’s write ... Read More

Detecting the largest element in an array of Numbers (nested) in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:55:28

204 Views

We have to write a simple function in JavaScript that takes in an array of Numbers (nested to any level) and return the greatest number present in the array.For example: If the input array is −const arr = [    34, 65, 67,    [       43, 76, ... Read More

Detecting the first non-unique element in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:53:28

168 Views

We are required to write a function that returns the index of the very first element that appears at least twice in the array. If no element appears more than once, we have to return -1. We have to do this in constant space (i.e., without utilizing extra memory).So, let's ... Read More

Using recursion to remove consecutive duplicate entries from an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:51:32

503 Views

We are supposed to write a function that takes in an array of number/string literals. The function should remove all the redundant consecutive elements of the array without using extra memory space.For example, if the input array is −const arr = [17, 17, 17, 12, 12, 354, 354, 1, 1, ... Read More

Combining the identical entries together in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:49:38

97 Views

We have an array of numbers that have got identical entries. We are required to write a function that takes in the array and groups all the identical entries into one subarray and returns the new array thus formed.For example: If the input array is −const arr = [234, 65, ... Read More

Array flattening using loops and recursion in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:48:03

627 Views

We are required to write a JavaScript array function that takes in a nested array with false values as well and returns an array with all the elements present in the array without any nesting.For example: If the input is −const arr = [[1, 2, 3], [4, 5, [5, false, ... Read More

If the element repeats, remove all its instances from array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:46:45

101 Views

We are required to write a function that takes in an array and returns a new array that have all duplicate values removed from it. The values that appeared more than once in the original array should not even appear for once in the new array.For example, if the input ... Read More

Keeping only alphanumerals in a JavaScript string in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Oct-2020 11:43:21

128 Views

We are required to write a JavaScript function that takes in a string that might contain some special characters.The function should return a new string should have all special characters replaced with their corresponding ASCII value.Therefore, let’s write the code for this function −ExampleThe code for this will be −const ... Read More

Advertisements