Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Find Minimum of two numbers using Absolute function

I have problem to find minimum of two numbers, and I found a formula but I think it is wrong this is ref

For Minimum: [(x + y + abs(x - y)) / 2] Here is the code I tried

function min(x,y){
/*    var min
    if(x>=y){
         min=y 
     }
     else{
         min=x
     }
     return min 
     */
     return [(x+y + Math.abs(x - y)) / 2]
}
var x,y;
alert("saisir deux nombre :");
x=+prompt('x:');
y=+prompt('y:');
alert("le min est : " + min(x,y) )
console.log(min(x,y))

Test

x: 1
y: 2
le min est : 2

But he must give me 1 instead!

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The actual formula is ((x + y - Math.abs(x - y)) / 2):

function minimum(x,y){
  return ((x + y - Math.abs(x - y)) / 2);
}

console.log(1, 2, 'minimum', minimum(1,2));
console.log(20, 10, 'minimum', minimum(20,10));
console.log(-20, 10, 'minimum', minimum(-20,10));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!