AmitDiwan has Published 10744 Articles

Finding the first redundant element in an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:53:51

193 Views

Let’s say, 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 ... Read More

Inserting element at falsy index in an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:51:31

191 Views

We are required to write an Array function, let’s say, pushAtFalsy() The function should take in an array and an element. It should insert the element at the first falsy index it finds in the array.If there are no empty spaces, the element should be inserted at the last of ... Read More

Alternative shuffle in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:50:25

344 Views

Alternative ShuffleAn alternatively shuffled array in JavaScript is an array of Numbers in which numbers are indexed such that greatest number is followed by the smallest element, second greatest element is followed by second smallest element and so on.For example: If the input array is −const arr = [11, 7, ... Read More

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

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:49:18

523 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

Grouping identical entries into subarrays - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:47:12

161 Views

Let’s say, 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 = ... Read More

Flattening an array with truthy/ falsy values without using library functions - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:46:05

158 Views

We are required to write a JavaScript array function that takes in a nested array with falsy values 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, 6, ... Read More

Converting array to object by splitting the properties - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:44:54

215 Views

We have an array of string literals in which each element has a dash (-), The property key is present to the left of dash and its value to the right. A sample input array would look something like this −const arr = ["playerName-Kai Havertz", "age-21", "nationality-German", "postion-CAM", "languages-German, English, ... Read More

Removing redundant elements from array altogether - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:43:39

309 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

Recursive product of all digits of a number - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:42:41

320 Views

We are required to write a JavaScript function that takes in a number and finds the product of all of its digits. If any digit of the number is 0, then it should be considered and multiplied as 1.For example − If the number is 5720, then the output should ... Read More

Replacing all special characters with their ASCII value in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 12:41:12

2K+ 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 valueExampleFollowing is the code −const str = 'Th!s !s @ str!ng th@t cont@!ns some ... Read More

Advertisements