AmitDiwan has Published 10740 Articles

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

AmitDiwan

AmitDiwan

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

134 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

805 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

631 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

238 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

539 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

408 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

498 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

149 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

476 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

How to access variables declared in a function, from another function using JavaScript?

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:44:57

2K+ Views

We have to write a function, that does some simple task, say adding two numbers or something like that. We are required to demonstrate the way we can access the variables declared inside that function in some other function or globally.ExampleFollowing is the code −const num = 5; const addRandomToNumber ... Read More

Advertisements