AmitDiwan has Published 10744 Articles

Alternatingly combining array elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:45:42

106 Views

ProblemWe are required to write a JavaScript function that takes in any number of arrays of literals as input.Our function should prepare a new array that contains elements picked alternatingly from all the input arrays.For example, if the input to the function is −Inputconst arr1 = [1, 2, 3, 4]; ... Read More

Arranging lexicographically and removing whitespaces in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:42:08

126 Views

ProblemWe are required to write a JavaScript function that takes in a string, str, that contains alphabets and whitespacesOur function should iterate over the input string and perform actions so that the characters are concatenated into a new string in "case-insensitively-alphabetical-order-of-appearance" order. Whitespace and punctuation shall simply be removed!For example, ... Read More

Crack Alphabets fight problem in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:39:35

147 Views

ProblemConsider a situation where armies of two bunch of alphabets are fighting each other. The soldiers of both and their weight are as follows −TeamASoldierWeightA1B2C3D4TeamBSoldierWeightW1X2Y3Z4Other than the soldiers, there are bombs as well in the arena denoted by ‘!’, and a bomb kills soldiers placed at its adjacent sides.For instance: ... Read More

Splitting number into n parts close to each other in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:34:55

1K+ Views

ProblemWe are required to write a JavaScript function that takes in a number, num, as the first argument and another number, parts, as the second argument.Our function should split the number num into exactly (parts) numbers and we should keep these two conditions in mind −The numbers should be as ... Read More

Counting adjacent pairs of words in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:30:50

305 Views

ProblemWe are required to write a JavaScript function that takes in a string str that represents a sentence as the only argument.Our function should count and return the adjacent pair of identical words present in the string str. Our function should check the words ignoring their case, which means ‘it’ ... Read More

Adding binary without converting in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:28:03

271 Views

ProblemWe are required to write a JavaScript function that takes in two binary strings str1 and str2 as the first and the second argumentOur function should return the sum of the two binary numbers. We are not allowed to convert the binary numbers into decimal and then add and the ... Read More

Computing Ackerman number for inputs in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:26:20

387 Views

Ackermann FunctionThe Ackermann Function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.ProblemWe are required to write a JavaScript function that takes in two numbers, m and ... Read More

ASCII to hex and hex to ASCII converter class in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:20:40

819 Views

ProblemWe are required to write a JavaScript class that have to member functions −toHex: It takes in a ASCII string and returns its hexadecimal equivalent.toASCII: It takes in a hexadecimal string and returns its ASCII equivalent.For example, if the input to the function is −Inputconst str = 'this is a ... Read More

Sorting one string by the order of second in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:14:29

219 Views

ProblemWe are required to write a JavaScript function that takes in two strings, str1 and str2 as the first and the second argument.Our function should sort str1 according to the order of characters as they appear in str2For example, if the input to the function is −Inputconst str1 = 'coding'; ... Read More

Finding length of repeating decimal part in JavaScript

AmitDiwan

AmitDiwan

Updated on 22-Apr-2021 11:10:41

378 Views

ProblemWe are required to write a JavaScript function that takes in a number, num, as the first and the only argumentOur function should do two thingsFirst of all, it should check whether the number is prime with 10 or not, if its not, we should return -1 (a number is ... Read More

Advertisements