AmitDiwan has Published 10744 Articles

Adding two values at a time from an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 10:00:25

2K+ Views

Let’s say, we are required to write a JavaScript function that takes in an array of Numbers and returns a new array with elements as sum of two consecutive elements from the original array.For example, if the input array is −const arr = [3, 6, 3, 87, 3, 23, 2, ... Read More

Splitting last n digits of each value in the array in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:58:01

100 Views

We have an array of literals like this −const arr = [56768, 5465, 5467, 3, 878, 878, 34435, 78799];We are required to write a JavaScript function that takes in this array and a number n and if the corresponding element contains more than or equal to n characters, then the ... Read More

Odd even index difference - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:55:08

775 Views

We are required to write a JavaScript function that takes in an array of numbers like this −const arr = [3, 6, 34, 12, 6, 8, 8, 5, 6, 8];The function should return the difference between the sum of elements present at the odd index and the sum of elements ... Read More

Matching strings for similar characters - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:53:31

571 Views

We are required to write a JavaScript function that accepts two string and a number n.The function matches the two strings i.e., it checks if the two strings contains the same characters.The function returns true if both the strings contain the same character irrespective of their order or if they ... Read More

Segregating a string into substrings - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:52:22

215 Views

We are required to write a JavaScript function that takes in a string and a number n as two arguments (the number should be such that it exactly divides the length of string) and we have to return an array of n strings of equal length.For example −If the string ... Read More

Sorting an array of binary values - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:50:37

491 Views

Let’s say, we have an array of Numbers that contains only 0, 1 and we are required to write a JavaScript function that takes in this array and brings all 1s to the start and 0s to the end.For example − If the input array is −const arr = [1, ... Read More

Arranging words in Ascending order in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:49:28

389 Views

Let’s say, we are required to write a JavaScript function that takes in a string and returns a new string with words rearranged according to their increasing length.ExampleFollowing is the code −const str = 'This is a sample string only'; const arrangeByLength = str => {    const strArr = ... Read More

Finding the ASCII score of a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:48:28

452 Views

ASCII CodeASCII is a 7-bit character code where every single bit represents a unique character.Every English alphabet has a unique decimal ascii code.We are required to write a JavaScript function that takes in a string and counts the sum of all the ascii codes of the string charactersExampleFollowing is the ... Read More

Function that parses number embedded in strings - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:47:07

123 Views

Conventionally, we have functions like parseInt() and parseFloat() that takes in a string and converts the number string to Number. But these methods fail when we have numbers embedded at random index inside the string.For example: The following would only return 454, but what we want is 4545453 −parseInt('454ffdg54hg53')So, we ... Read More

Reverse sum of two arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:46:03

453 Views

We are required to write a JavaScript function that takes in two arrays of numbers of the same length. The function should return an array with any arbitrary nth element of the array being the sum of nth term from start of first array and nth term from last of ... Read More

Advertisements