AmitDiwan has Published 10744 Articles

Next multiple of 5 and binary concatenation in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:55:54

115 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should return the next higher multiple of five of that number, obtained by concatenating the shortest possible binary string to the end of this number's binary representation.ExampleFollowing is the code −const generateAll = (num ... Read More

Checking if a string contains all unique characters using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:55:37

369 Views

ProblemWe are required to write a JavaScript function that takes in a sting and returns true if all the characters in the string appear only once and false otherwise.ExampleFollowing is the code − Live Democonst str = 'thisconaluqe'; const allUnique = (str = '') => {    for(let i = 0; ... Read More

Validating a boggle word using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:55:19

497 Views

ProblemA Boggle board is a 2D array of individual characters, e.g. −const board = [    ["I", "L", "A", "W"],    ["B", "N", "G", "E"],    ["I", "U", "A", "O"],    ["A", "S", "R", "L"] ];We are required to write a JavaScript function that takes in boggle board and a ... Read More

Product sum difference of digits of a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:54:53

220 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should find the absolute difference between the sum and the product of all the digits of that number.ExampleFollowing is the code − Live Democonst num = 434312; const sumProductDifference = (num = 1) => { ... Read More

Returning the value of (count of positive / sum of negatives) for an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:54:17

599 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers (positives and negatives) and our function should return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers.ExampleFollowing is the code − Live Democonst arr ... Read More

Python Program to Check If Two Numbers are Amicable Numbers

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:53:57

823 Views

Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. When it is required to check if two numbers are amicable numbers, a method can be defined that iterates over the number, and uses the modulus operator. ... Read More

Python Program to Compute a Polynomial Equation given that the Coefficients of the Polynomial are stored in a List

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:53:37

1K+ Views

When it is required to compute a polynomial equation when the coefficients of the polynomial are stored in a list, a simple ‘for’ loop can be used.Below is the demonstration of the same −Example Live Demomy_polynomial = [2, 5, 3, 0] num = 2 poly_len = len(my_polynomial) my_result = 0 for ... Read More

Python Program to Check if a Number is a Strong Number

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:53:09

7K+ Views

Strong number is a number whose sum of all digits’ factorial is equal to the number ‘n’. Factorial implies when we find the product of all the numbers below that number including that number and is denoted by ! (Exclamation sign), For example: 5! = 5x4x3x2x1 = 120. When it ... Read More

Python Program to Check if a Number is a Perfect Number

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:52:51

3K+ Views

A number is said to be a Perfect Number when that is equal to the sum of all its positive divisors except itself. When it is required to check if a number is a perfect number, a simple ‘for’ loop can be used.Below is the demonstration of the same −Example Live ... Read More

Python Program to Print the Pascal's triangle for n number of rows given by the user

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 10:52:34

610 Views

When it is required to print the pascal’s triangle for a specific number of rows, where the number is entered by the user, a simple ‘for’ loop is used.Below is the demonstration of the same −Example Live Demofrom math import factorial input = int(input("Enter the number of rows...")) for i ... Read More

Advertisements