AmitDiwan has Published 10744 Articles

Alternate addition multiplication in an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 09:04:14

241 Views

We are required to write a JavaScript function that takes in an array of numbers and returns the alternative multiplicative sum of the elementsFor example −If the array is −const arr = [1, 2, 4, 1, 2, 3, 4, 3];then the output should be calculated like this −1*2+4*1+2*3+4*3 2+4+6+12And the ... Read More

Convert object to a Map - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 09:02:18

1K+ Views

Suppose we have an object like this −const obj = {    name: "Vikas",    age: 45,    occupation: "Frontend Developer",    address: "Tilak Nagar, New Delhi",    experience: 23,  };We are required to write a JavaScript function that takes in such an object with key value pairs and converts ... Read More

Convert nested array to string - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 08:58:44

518 Views

We are required to write a JavaScript function that takes in a nested array of literals and converts it to a string by concatenating all the values present in it to the stringconst arr = [    'hello', [       'world', 'how', [          'are', ... Read More

Comparing ascii scores of strings - JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 08:55:05

1K+ 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 function that takes in two strings and calculates their ascii scores (i.e., the sum of ascii decimal of each character of string) ... Read More

Comparing forEach() and reduce() for summing an array of numbers in JavaScript.

AmitDiwan

AmitDiwan

Updated on 15-Sep-2020 08:52:42

451 Views

We are required to compare the time taken respectively by the ES6 functions forEach() and reduce() for summing a huge array of numbers.As we can't have a huge array of numbers here, we will simulate the magnitude of array by performing the summing operation for large number of times (iterations)ExampleLet's ... Read More

Prime numbers in a range - JavaScript

AmitDiwan

AmitDiwan

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

1K+ Views

We are required to write a JavaScript function that takes in two numbers, say, a and b and returns the total number of prime numbers between a and b (including a and b, if they are prime).For example −If a = 2, and b = 21, the prime numbers between ... Read More

Finding least number of notes to sum an amount - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:39:10

768 Views

Suppose, we have a currency system where we have denominations of 1000 units, 500 units, 100 units, 50 units, 20 units, 10 units, 5 units, 2 units and 1 unit.Given a specific amount, we are required to write a function that calculates the least number of total denominations that sum ... Read More

Program to append two given strings such that, if the concatenation creates a double character then omit one of the characters - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:32:14

194 Views

We are required to write a JavaScript function that takes in two strings and concatenates the second string to the first string.If the last character of the first string and the first character of the second string are the same then we have to omit one of those characters. Let’s ... Read More

Check for perfect square without using Math libraries - JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:30:36

370 Views

We are required to write a JavaScript function that takes in a number and returns a boolean based on the fact whether or not the number is a perfect square.Examples of perfect square numbers −4, 16, 81, 441, 256, 729, 9801Let’s write the code for this function −const num = ... Read More

Getting tomorrow and day after tomorrow date in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 14:28:39

776 Views

Using the Date class of JavaScript whose object new Date() returns a JavaScript date for the current day, we have to find the date of the next two days.This is a fairly simple problem and we can achieve this with a few lines of code. At first, get today’s date ... Read More

Advertisements