orderedmap icon indicating copy to clipboard operation
orderedmap copied to clipboard

[feature request] a way to break `forEach` - or add `some` ?

Open kapouer opened this issue 8 years ago • 1 comments

It can be frustrating to loop over each key, value when searching for one value in particular.

kapouer avatar Jan 20 '17 13:01 kapouer

Default implementation for this

  // :: (any, string, index) → boolean
  // Takes a predicate function that takes 3 arguments
  // Value, key, index
  // Returns true if any item matches the predicate, false otherwise
  some: function(predicate) {
    for (var i = 1; i < this.content.length; i += 2)
      if (predicate(this.content[i], this.content[i-1], i/2)) return true
    return false
  },

Tezraine avatar Jul 22 '23 11:07 Tezraine