Facebook
From Abreu, 3 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 61
  1. // myFunction receives an array of objects and a limit amount
  2. // it should return an array containing the decisions that have amounts <= limit
  3. // if the min_amount <= limit && max_amount >= limit, the value should be replaced by the limit amount
  4.  
  5. // Example:
  6.  
  7. const decisions = [
  8.     {
  9.         grade: 'A',
  10.         min_amount: 3500,
  11.         max_amount: 4375,
  12.     },
  13.     {
  14.         grade: 'B',
  15.         min_amount: 4375,
  16.         max_amount: 5250,
  17.     },
  18.     {
  19.         grade: 'C',
  20.         min_amount: 5250,
  21.         max_amount: 6125,
  22.     },
  23.     {
  24.         grade: 'D',
  25.         min_amount: 6125,
  26.         max_amount: 7000,
  27.     }];
  28.  
  29. const limit = 5693;
  30. const result = myFunction(decisions, limit);
  31. console.log(result);
  32. /*
  33. [ { grade: 'A', min_amount: 3500, max_amount: 4375 },
  34.   { grade: 'B', min_amount: 4375, max_amount: 5250 },
  35.   { grade: 'C', min_amount: 5250, max_amount: 5693 } ] ;
  36. */