AmitDiwan has Published 10744 Articles

Finding one missing number in a scrambled sequence using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:08:03

250 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers containing numbers from 1 to n.The problem is that one number from the array goes missing and the array is not sorted as well. Our function should find and return that one number missing from ... Read More

Finding all solutions of a Diophantine equation using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:07:46

278 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should find all such number x and y such that −x^2 - 4y^2 = n.And it should return an array of all such pairs.ExampleFollowing is the code − Live Democonst num = 90005; const findSolution ... Read More

Smallest possible number divisible by all numbers from 1 to n in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:05:36

169 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should find and return that smallest possible number which is divisible by all numbers from 1 to n.ExampleFollowing is the code − Live Democonst num = 11; const smallestDivisible = (num = 1) => { ... Read More

Python Program to Create a List of Tuples with the First Element as the Number and Second Element as the Square of the Number

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:04:09

3K+ Views

When it is required to create a list of tuple, and have the first element as the number, and the second element as the square of the element, list comprehension can be used.Below is the demonstration of the same −Example Live Demomy_list = [23, 42, 67, 89, 11, 32] print(“The list ... Read More

Python Program to Find the Second Largest Number in a List Using Bubble Sort

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:03:51

930 Views

When it is required to find the second largest number in a list using bubble sort, a method named ‘bubble_sort’ is defined, that sorts the elements of the list. Once this is done, another method named ‘get_second_largest’ is defined that returns the second element from the end as output.Below is ... Read More

Python Program to Merge Two Lists and Sort it

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:03:33

2K+ Views

When it is required to merge two lists and sort them, a method can be defined that sorts the list using ‘sort’ method.Below is the demonstration of the same −Example Live Demodef merge_list(list_1, list_2):    merged_list = list_1 + list_2    merged_list.sort()    return(merged_list) list_1 = [20, 18, 9, 51, ... Read More

Python Program to Find the Gravitational Force Acting Between Two Objects

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:02:59

457 Views

When it is required to find the gravitational force that acts between the two objects, a method named ‘find_gravity’ is used, and three parameters are passed to it.Below is the demonstration of the same −Example Live Demodef find_gravity(m_1, m_2, r):    G_val = 6.673*(10**-11)    F_val = (G_val*m_1*m_2)/(r**2)    return ... Read More

Merging two sorted arrays into one sorted array using JavaScript

AmitDiwan

AmitDiwan

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

1K+ Views

ProblemWe are required to write a JavaScript function that takes in two sorted arrays of numbers our function should merge all the elements of both the arrays into a new array and return that new array sorted in the same order.ExampleFollowing is the code − Live Democonst arr1 = [1, 3, ... Read More

Finding the longest non-negative sum sequence using JavaScript

AmitDiwan

AmitDiwan

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

187 Views

ProblemWe are required to write a JavaScript function that takes in an array containing a sequence of integers, each element of which contains a possible value ranging between -1 and 1.Our function should return the size of the longest sub-section of that sequence with a sum of zero or higher.ExampleFollowing ... Read More

Is the reversed number a prime number in JavaScript

AmitDiwan

AmitDiwan

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

303 Views

ProblemWe are required to write a JavaScript function that takes in a number and return true if the reverse of that number is a prime number, false otherwise.ExampleFollowing is the code − Live Democonst num = 13; const findReverse = (num) => {    return +num    .toString()    .split('')   ... Read More

Advertisements