Return Two Numbers Whose Sum is N and Product M in JavaScript



We are required to write a JavaScript function that takes in two numbers, say m and n and returns two numbers whose sum is n and product is m. If there exist no such numbers, then our function should return false

Let’s write the code for this function −

Example

const perfectNumbers = (sum, prod) => {
   for(let i = 0; i 

Output

Following is the output in the console −

false
[ 5, 9 ]
[ 7, 14 ]
Updated on: 2020-09-14T13:57:55+05:30

179 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements