Skip to content

Commit

Permalink
Exchange: support null as undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
egorFiNE committed Jun 5, 2018
1 parent 4f8221c commit eb34b9a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions js/base/Exchange.js
Expand Up @@ -903,25 +903,25 @@ module.exports = class Exchange {
}

filterBySinceLimit (array, since = undefined, limit = undefined) {
if (typeof since !== 'undefined')
if (typeof since !== 'undefined' && since !== null)
array = array.filter (entry => entry.timestamp >= since)
if (typeof limit !== 'undefined')
if (typeof limit !== 'undefined' && limit !== null)
array = array.slice (0, limit)
return array
}

filterBySymbolSinceLimit (array, symbol = undefined, since = undefined, limit = undefined) {

const symbolIsDefined = typeof symbol !== 'undefined'
const sinceIsDefined = typeof since !== 'undefined'
const symbolIsDefined = typeof symbol !== 'undefined' && symbol !== null
const sinceIsDefined = typeof since !== 'undefined' && since !== null

// single-pass filter for both symbol and since
if (symbolIsDefined || sinceIsDefined)
array = Object.values (array).filter (entry =>
((symbolIsDefined ? (entry.symbol === symbol) : true) &&
(sinceIsDefined ? (entry.timestamp >= since) : true)))

if (typeof limit !== 'undefined')
if (typeof limit !== 'undefined' && limit !== null)
array = Object.values (array).slice (0, limit)

return array
Expand All @@ -932,7 +932,7 @@ module.exports = class Exchange {
objects = Object.values (objects)

// return all of them if no values were passed
if (typeof values === 'undefined')
if (typeof values === 'undefined' || values === null)
return indexed ? indexBy (objects, key) : objects

let result = []
Expand Down

0 comments on commit eb34b9a

Please sign in to comment.