AmitDiwan has Published 10740 Articles

Armstrong number within a range in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:56:08

459 Views

Armstrong Numbers: A positive integer is called an Armstrong number (of order n) if −abcd... = a^n + b^n + c^n + d^n + ...We are required to write a JavaScript function that takes in an array of exactly two numbers specifying a range.The function should return an array of ... Read More

Splitting array of numbers into two arrays with same average in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:54:29

257 Views

We are required to write a JavaScript function that takes in an array of integers as the first and the only argument.The function needs to determine whether there exists a combination of elements of the input array that when they are divided into two groups (may/may not have equal elements), ... Read More

Similar string groups in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:52:40

431 Views

Two strings str1 and str2 are similar if we can swap two letters (in different positions) of str1, so that it equals str2. Also, two strings str1 and str2 are similar if they are equal.For example, "tars" and "rats" are similar (swapping at positions 0 and 2), and "rats" and ... Read More

Finding missing element in an array of numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:47:46

1K+ Views

We are required to write a JavaScript function that takes in an array of numbers of length, say n. The array contains all the integers from 0 to n (including both 0 and n), but just one integer is missing, it can be any number and the array is not ... Read More

Prime digits sum of a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:46:36

334 Views

We are required to write a JavaScript function that takes in a number as the first and the only argument. The function should then sum all the digits of the number that are prime and return the sum as a number.For example −If the input number is −const num = ... Read More

How to create permutation of array with the given number of elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:45:15

244 Views

We are required to write a JavaScript function that takes in an array of literals as the first argument and a number as the second argument.The function should construct an array of all such arrays which have the length equal to the number specified by the second argument and contains ... Read More

Adding numbers represented by string without complete conversion in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:43:24

819 Views

We are required to write a JavaScript function that takes in two strings, str1 and str2 that represents two numbers.Without converting the whole strings to respective numbers, our function should calculate the sum of those two string numbers and return the result as a string.For example −If the two strings ... Read More

Finding the first non-repeating character of a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:41:53

502 Views

We are required to write a JavaScript function that takes in a string as the first and the only argument.The function should find and return the index of first character it encounters in the string which appears only once in the string.If the string does not contain any unique character, ... Read More

Finding desired numbers in a sorted array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:40:01

221 Views

We have an array of integers which is sorted in the increasing order. We are required to write a JavaScript function that takes in one such array as the first argument and a target sum number as the second argument.The function should find and return two such numbers from the ... Read More

Finding the length of second last word in a sentence in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Jan-2021 06:37:24

503 Views

A sentence is just a string which contains strings (called words) joined by whitespaces. We are required to write a JavaScript function that takes in one such sentence string and count the number of characters in the second to last word of the string. If the string contains no more ... Read More

Advertisements