Search code examples
javascriptfunction

Javascript function to get the absolute difference between two numbers


I want a Simple Javascript function to get the difference between two numbers in such a way that foo(2, 3) and foo(3,2) will return the same difference 1.


Solution

  • var difference = function (a, b) { return Math.abs(a - b); }