<commit_before>requirejs = require('requirejs')

requirejs(['chai', 'underscore'], function(chai, _) {
  var expect = chai.expect

  function GroupedArray(array) {
    this.array = array
  }

  GroupedArray.prototype.groupBy = function(func) {
    this.groups = {}
    for(var i=0; i<this.array.length; i++) {
      var item = this.array[i]
      var value = func(item)
      var group = this.groups[value] || (this.groups[value] = {value: value, items: []})
      group.items.push(item)
    }
    return this
  }

  GroupedArray.prototype.splice = function() {
    Array.prototype.splice.apply(this.array, arguments)
  }

  function test() {
    var array = [1,2,3]
    var grouped = new GroupedArray(array).groupBy(function(number) {
      return number > 2
    })
    expect(grouped.groups).to.have.all.keys('false', 'true')
    expect(grouped.groups[false].items).to.have.members([1,2])
    expect(grouped.groups[true].items).to.have.members([3])

    // Adding 
    grouped.splice(1, 0, 27)
    expect(array).to.have.members([1,27,2,3])
    // expect(grouped.groups).to.have.members([3,27])
    console.log('dooooooooooooon!')
  }

  test()
})<commit_msg>GroupedArray is only contiguous groups<commit_after>requirejs = require('requirejs')

requirejs(['chai', 'underscore'], function(chai, _) {
  var expect = chai.expect

  function GroupedArray(array) {
    this.array = array
  }

  GroupedArray.prototype.groupBy = function(func) {
    this.groupingFunction = func
    this.groups = []
    var lastGroup
    for(var i=0; i<this.array.length; i++) {
      var item = this.array[i]
      var value = func(item)
      var isNewGroup = lastGroup && value != lastGroup.value
      var isLastItem = i == this.array.length - 1

      if (isNewGroup) {
        this.groups.push(lastGroup)
        lastGroup = null
      }

      if (!lastGroup) {
        lastGroup = {value: value, items: []}
      }

      lastGroup.items.push(item) 

      if (isLastItem) { 
        this.groups.push(lastGroup)
      }
    }

    return this
  }

  GroupedArray.prototype.splice = function() {
    //Array.prototype.splice.apply(this.array, arguments)
    //var newItems = arguments.slice(2)
    //var values = newItems.map(this.groupingFunction)
  }

  function test() {
    var array = [1,2,3,0]
    var grouped = new GroupedArray(array).groupBy(function(number) {
      return number > 2
    })
    expect(grouped.groups).to.have.length(3)

    expect(grouped.groups[0].value).to.equal(false) // not greater than two
    expect(grouped.groups[0].items).to.have.members([1,2])

    expect(grouped.groups[1].value).to.equal(true)  // YES greater than 2
    expect(grouped.groups[1].items).to.have.members([3])

    expect(grouped.groups[2].value).to.equal(false)  // also not greater than 2
    expect(grouped.groups[2].items).to.have.members([0])

    // Adding 
    // grouped.splice(1, 0, 27)
    // expect(array).to.have.members([1,27,2,3])
    // expect(grouped.groups[true].items).to.have.members([3,27])
    console.log('dooooooooooooon!')
  }

  test()
})
{'fraction_non_alphanumeric': 0.16022280471821757, 'fraction_numerical': 0.017365661861074706, 'mean_word_length': 2.9960732984293195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1596508', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1038, 'n_words': 173}