Advertisement
CLooker

Untitled

Jan 30th, 2018
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem
  2.  
  3. function breakingRecords(scores) {
  4.   let e = scores.reduce((recordsObj, s, index) => {
  5.     index === 0 ?
  6.       (
  7.         recordsObj.low = s,
  8.         recordsObj.high = s
  9.       ) :
  10.       null;
  11.     s < recordsObj.low ? (recordsObj.low = s, recordsObj.lowCounter++) : null;
  12.     s > recordsObj.high ? (recordsObj.high = s, recordsObj.highCounter++) : null;
  13.     return recordsObj;
  14.   }, {
  15.     low: 0,
  16.     lowCounter: 0,
  17.     high: 0,
  18.     highCounter: 0
  19.   });
  20.   return [e.highCounter, e.lowCounter];
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement