AmitDiwan has Published 10744 Articles

How to store two arrays as a keyvalue pair in one object in JavaScript?

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:26:07

735 Views

Suppose, we have two arrays of literals of same length like these −const arr1 = ['firstName', 'lastName', 'age', 'address', 'isEmployed']; const arr2 = ['Rahul', 'Sharma', 23, 'Tilak Nagar', false];We are required to write a JavaScript function that takes in two such arrays.The function should construct an object mapping the elements ... Read More

Program to make vowels in string uppercase and change letters to next letter in alphabet (i.e. z->a) in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:24:56

517 Views

We are required to write a JavaScript function that takes in a string as the only input.The function should construct a new string based on the input string in which all the vowels should be uppercased and change each alphabet to the corresponding next alphabet.For example − If the input ... Read More

Reversing the alphabet from back to front and front to back in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:23:26

262 Views

We are required to write a JavaScript function that takes in a single alphabet as the only input. The function should compute the position of the that alphabet from starting and return an alphabet that’s at the same position but from the back.ExampleThe code for this will be −const alpha ... Read More

Possible combinations and convert into alphabet algorithm in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:21:52

230 Views

Suppose we are given the mapping a = 1, b = 2, ... z = 26, and an encoded message. We are required to write a JavaScript function that takes in the message.The function should count the number of ways it can be decoded.For example, the message '111' would give ... Read More

Expressive words problem case in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:20:37

205 Views

Sometimes people repeat letters to represent extra feeling, such as "hello" −> "heeellooo", "hi" −> "hiiii". In these strings like "heeellooo", we have groups of adjacent letters that are all the same: "h", "eee", "ll", "ooo".For some given string S, a query word is stretchy if it can be made ... Read More

Indexing numbers to alphabets in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:19:27

2K+ Views

We are required to write a JavaScript function that takes in a number between the range [0, 25], both inclusive.Return valueThe function should return the corresponding alphabets for that number.ExampleThe code for this will be −const num = 15; const indexToAlpha = (num = 1) => {    // ASCII ... Read More

Sorting elements of stack using JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:18:14

282 Views

We are required to write a JavaScript function that takes in an array of Integers. Making use of recursion and the push and pop methods of the array, the function should sort the array inplace.ExampleThe code for this will be −const stack = [−3, 14, 18, −5, 30]; const sortStack ... Read More

Prefix calculator using stack in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:16:59

1K+ Views

We are required to make a calculator with the RPN (reverse polish notation) input method using Stacks in JavaScript.Consider the following input array −const arr = [1, 5, '+', 6, 3, '-', '/', 7, '*'];Process −1 is an operand, push to Stack.5 is an operand, push to Stack.'+' is an ... Read More

Implementing Heap Sort using vanilla JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:15:20

230 Views

Heap Sort is basically a comparison-based sorting algorithm. It can be thought of as an improved selection sort − like that algorithm, it divides its input into a sorted and an unsorted region, and it interactively shrinks the unsorted region by extracting the target (largest or smallest) element and moving ... Read More

Binary to original string conversion in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 11:14:10

410 Views

We are required to write a JavaScript function that takes in a string that represents a binary code. The function should return the alphabetical representation of the string.For example −If the binary input string is −const str = '1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100';Then the ... Read More

Advertisements