AmitDiwan has Published 10740 Articles

JavaScript - Constructs a new array whose elements are the difference between consecutive elements of the input array

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:54:44

167 Views

Suppose, we have an array of numbers like this −const arr = [3, 5, 5, 23, 3, 5, 6, 43, 23, 7];We are required to write a function that takes in one such array and constructs another array whose elements are the difference between consecutive elements of the input array.For ... Read More

Diagonal product of a matrix - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:52:25

2K+ Views

Suppose, we have a 2-D array representing a square matrix like this −const arr = [    [1, 3, 4, 2],    [4, 5, 3, 5],    [5, 2, 6, 4],    [8, 2, 9, 3] ];We are required to write a function that takes in this array and returns ... Read More

Twice repetitive word count in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:50:23

1K+ Views

We are required to write a JavaScript function that takes in a string that contains some words that are repeated twice, we need to count such words.For example −If the input string is −const str = "car bus jeep car jeep bus motorbike truck";Then the output should be −3ExampleFollowing is ... Read More

Change string based on a condition - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:47:31

787 Views

We are required to write a JavaScript function that takes in a string. The task of our function is to change the string according to the following condition −If the first letter in the string is a capital letter then we should change the full string to capital letters.Otherwise, we ... Read More

JavaScript - Check if array is sorted (irrespective of the order of sorting)

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:45:15

521 Views

We are required to write a JavaScript function that takes in an array of literals and checks if the array is sorted or not (irrespective of the order of sorting.)Our function should return true if the array is sorted, false otherwise. Following is the code −Exampleconst arr = [1, 3, ... Read More

Squared sum of n odd numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:43:14

313 Views

We are required to write a JavaScript function that takes in a Number, say n, and finds the sum of the square of first n odd natural Numbers.For example −If the input number is 3. Then the output will be −1^2 + 3^2 + 5^2 = 35Therefore, the output is ... Read More

Check whether sum of digit of a number is Palindrome - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:41:24

657 Views

We are required to write a JavaScript function that takes in a number, sums its digits and checks whether that sum is a Palindrome number or not. The function should return true if the sum is Palindrome, false otherwise.For example, if the number is 697, then the sum of its ... Read More

Swap kth element of array - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:39:36

641 Views

We are required to write a JavaScript function that accepts an array of Numbers and a number, say k (k must be less than or equal to the length of array).And our function should replace the kth element from the beginning with the kth element from the end of the ... Read More

Split string into groups - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:37:43

296 Views

Given a string S which consists of alphabets, numbers and special characters.We need to write a program to split the strings in three different strings S1, S2 and S3, such thatThe string S1 will contain all the alphabets present in S, The string S2 will contain all the numbers present ... Read More

Count number of factors of a number - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 11:33:47

485 Views

We are required to write a JavaScript function that takes in a number and returns the count of numbers that exactly divides the input number.For example −If the number is 12, then its factors are −1, 2, 3, 4, 6, 12Therefore, the output should be 6.ExampleFollowing is the code −const ... Read More

Advertisements