js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Compare within margin #525

Closed RazvanBugoi closed 4 years ago

RazvanBugoi commented 4 years ago

https://www.codewars.com/kata/56453a12fcee9a6c4700009c/train/javascript

RazvanBugoi commented 4 years ago
function closeCompare(a, b, margin = 0){
  if (margin >= (Math.max(a,b) - Math.min(a,b))) {
    return 0;
  } else if(a < b) {
    return -1;
  } else return 1;
}