AmitDiwan has Published 10744 Articles

Pairing an array from extreme ends in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:19:14

169 Views

We are required to write a JavaScript function that takes in an array of Number / String literals and returns another array of arrays. With each subarray containing exactly two elements, the nth element from start nth from last.For example: If the array is −const arr = [1, 2, 3, ... Read More

Return a map representing the frequency of each data type in an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:17:31

112 Views

We are required to write a JavaScript function that takes in an array that contains elements of different data types and the function should return a map representing the frequency of each data type.Let’s say the following is our array −const arr = [23, 'df', undefined, null, 12, {   ... Read More

Finding the continuity of two arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:15:50

155 Views

We are required to write a JavaScript function that takes in two arrays of numbers. And the function should return true if the two arrays upon combining and shuffling can form a consecutive sequence, false otherwise.For example: If the arrays are −const arr1 = [4, 6, 2, 9, 3]; const ... Read More

Function to find the length of the second smallest word in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:13:53

167 Views

We are required to write a JavaScript function that takes in a string sentence as first and the only argument. And the function should return the length of the second smallest word from the string.For example: If the string is −const str = 'This is a sample string';Then the output ... Read More

Function that only replaces character from string after specified appearances in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:12:19

112 Views

We are required to write a JavaScript function that takes in a string as the first argument, a number, say n, as the second argument and a character, say c, as the third argument. The function should replace the nth appearance of any character with the character provided as the ... Read More

Return a subarray that contains all the element from the original array that are larger than all the elements on their right in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:10:37

125 Views

We are required to write a JavaScript function that takes in an array of numbers and returns a subarray that contains all the element from the original array that are larger than all the elements on their right.Therefore, let’s write the code for this function −ExampleThe code for this will ... Read More

Finding the validity of a hex code in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Oct-2020 10:09:04

186 Views

A string can be considered as a valid hex code if it contains no characters other than the 0-9 and a-f alphabets.For example:'3423ad' is a valid hex code '4234es' is an invalid hex codeWe are required to write a JavaScript function that takes in a string and checks whether its ... Read More

How many times can we sum number digits in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:48:08

145 Views

We are required to write a JavaScript function that takes in an positive integer and returns its additive persistence.The additive persistence of an integer, say n, is the number of times we have to replace the number with the sum of its digits until the number becomes a single digit ... Read More

Check if the elements of the array can be rearranged to form a sequence of numbers or not in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:46:11

142 Views

We are required to write a JavaScript function that takes in an array of numbers and checks if the elements of the array can be rearranged to form a sequence of numbers or not.For example: If the array is −const arr = [3, 1, 4, 2, 5];Then the output should ... Read More

Finding special kind of sentences (smooth) in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Oct-2020 11:44:04

239 Views

We are required to write a JavaScript function that checks whether a sentence is smooth or not.A sentence is smooth when the first letter of each word in the sentence is the same as the last letter of its preceding word.Therefore, let’s write the code for this function −ExampleThe code ... Read More

Advertisements