AmitDiwan has Published 10744 Articles

Split Array by part base on N count in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 08:00:59

336 Views

We are required to write a JavaScript function that takes in an array of literals and a number, say n.The function should return a new array, chunked into n subarrays, given that n will always be less than or equal to the length of the array.For example: If the input ... Read More

Reversing words in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:59:33

2K+ Views

We are required to write a JavaScript function that takes in a string. The function should return a new string that has all the words of the original string reversed.For example, If the string is −const str = 'this is a sample string';Then the output should be −const output = ... Read More

Check if an array is descending, ascending or not sorted in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:57:59

1K+ Views

We are required to write a JavaScript function that takes in an array of Numbers. The function should check whether the numbers in the array are in increasing order, or in decreasing order or in no specific order.If the array contains only one element then we should return a message ... Read More

Recursively adding digits of a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:56:16

199 Views

We are required to write a JavaScript function that takes in a number and recursively adds the digits of the number until the result is not a single digit number.For example, If the number is −54563Then the output should be 5, because, = 5 + 4 + 5 + 6 ... Read More

How to convert array into array of objects using map() and reduce() in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:54:46

927 Views

Suppose we have an array of arrays like this −const arr = [    [       ['juice', 'apple'], ['maker', 'motts'], ['price', 12]    ],    [       ['juice', 'orange'], ['maker', 'sunkist'], ['price', 11]    ] ];We are required to write a JavaScript function that takes in ... Read More

How to convert array of decimal strings to array of integer strings without decimal in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:52:49

690 Views

We are required to write a JavaScript function that takes in an array of decimal strings. The function should return an array of strings of integers obtained by flooring the original corresponding decimal values of the array.For example, If the input array is −const input = ["1.00", "-2.5", "5.33333", "8.984563"];Then ... Read More

Group by element in array JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:50:13

425 Views

Suppose, we have an array of objects like this −const arr = [    {"name": "toto", "uuid": 1111},    {"name": "tata", "uuid": 2222},    {"name": "titi", "uuid": 1111} ];We are required to write a JavaScript function that splits the objects into separate array of arrays that have the similar values ... Read More

Find array elements that are out of order in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:48:25

273 Views

Suppose we have an array of sorted numbers but some elements of the array are out of their sorted order.We are required to write a JavaScript function that takes in one such array and returns a subarray of all those elements that are out of order.ExampleThe code for this will ... Read More

Converting strings to snake case in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:46:19

682 Views

Snake case is basically a style of writing strings by replacing the spaces with '_' and converting the first letter of each word to lowercase.We are required to write a JavaScript function that takes in a string and converts it to snake case.ExampleThe code for this will be −const str ... Read More

Return the index of first character that appears twice in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 10-Oct-2020 07:44:27

294 Views

We are required to write a JavaScript function that takes in a string and returns the index of first character that appears twice in the string.If there is no such character then we should return -1.ExampleThe code for this will be −const str = 'Hello world, how are you'; const ... Read More

Advertisements