1

Please could you help me sort array which I get using $..balanceChange. It is a small part of response.

I need it for assertion in SoapUI.

 {
      "id": 182,
      "name": "49899 Consol Sick w S&S Pattern",
      "eventDefinition":       {
         "id": 111,
         "name": "49899 Consol Sick w S&S Pattern",
         "shortName": null,
         "displayName": "49899 Consol Sick w S&S Pattern",
         "active": true,
         "group": null,
         "lowerThresholdAmount": 0,
         "upperThresholdAmount": 0,
         "lowerThresholdDayAmount": null,
         "upperThresholdDayAmount": null,
         "amountUnit": null,
         "exceptionType": null,
         "comment": null,
         "paycode": null,
         "paycodeAmountType": null,
         "usedType": null,
         "punchType": null,
         "type": {"name": "pattern"},
         "extendedData": null,
         "dayBased": false
      },
      "policyDefinition":       {
         "id": 404,
         "name": "49899 Consolidated Sick w S&S plc467381724319"
      },
      "ruleDefinition":       {
         "id": 604,
         "name": "WR467381724319"
      },
      "pointTransaction":       {
         "id": 313,
         "name": "Attendance Points 1",
         "employeeId": 385,
         "balanceChange": 5,
         "typeCategory": "POINT",
         "applyDate": "2016-04-28T00:00:00"
      },
      "type": {"name": "pattern"},
      "employeeId": 385,
      "applyDate": "2016-04-28",
      "eventTime": "00:00:00",
      "amount": null,
      "dayAmount": null,
      "updatedByUserId": 12,
      "isSystem": true
   }
Rao
  • 20,781
  • 11
  • 57
  • 77
  • 1
    How do you want to sort it (Id, name or by object)? Could you give more explanation? – Anton Jul 01 '16 at 15:11
  • When it $..balanceChange execute, I have got [9.0, 8.0, 9.0, 8.0, 8.0, 8.0, 6.0, 5.0]. But sometimes this sequence is change and I can get [8.0, 9.0, 9.0, 8.0, 8.0, 8.0, 6.0, 5.0]. I need to sort this array by balanceChange – Алексей Спириденок Jul 01 '16 at 15:33
  • So, the simple way is use underscore. See answer may be it can help you, if not I will try to rewrite the code, just let me know – Anton Jul 01 '16 at 15:35
  • the example you have shown does not contains any of the values like 9.0, 8.0 etc. – Rao Jul 01 '16 at 17:06

1 Answers1

-4

Try to use underscore.js lib. Plunker

   var arr  = [
  { 
  "id": 182,
  "name": "49899 Consol Sick w S&S Pattern"
},
{ 
  "id": 183,
  "name": "49900 Consol Sick w S&S Pattern"
},{ 
  "id": 184,
  "name": "49901 Consol Sick w S&S Pattern"
},{ 
  "id": 185,
  "name": "49902 Consol Sick w S&S Pattern"
},{ 
  "id": 186,
  "name": "49903 Consol Sick w S&S Pattern"
},]


console.log(_.sortBy(arr, 'id'))

or just simplest (example in plunker)

var data = [9.0, 8.0, 9.0, 8.0, 8.0, 8.0, 6.0, 5.0]
console.log(data.sort());
Anton
  • 788
  • 4
  • 14
  • 34