@juancarlospaco, gracias!

Finally I managed to get it working with:

  * `crossfilter.nim`


    
    
    import jsffi
    
    when not defined(js):
      {.error: "This module only works on the JavaScript platform".}
    
    type
      Crossfilter* = ref object
    
    proc crossfilter*(a:openArray[JsObject]): Crossfilter 
{.importc:"crossfilter".}
    
    proc groupAll*(this:Crossfilter):Crossfilter {.importcpp.}
    
    proc reduceCount*(this:Crossfilter):Crossfilter {.importcpp.}
    
    proc value*(this:Crossfilter):int {.importcpp.}
    
    
    Run

  * `example.nim`


    
    
    import crossfilter, jsffi
    
    let data = @[
      js{ name: "Rusty",  type: "human", legs: 2 },
      js{ name: "Alex",   type: "human", legs: 2 },
      js{ name: "Lassie", type: "dog",   legs: 4 },
      js{ name: "Spot",   type: "dog",   legs: 4 },
      js{ name: "Polly",  type: "bird",  legs: 2 },
      js{ name: "Fiona",  type: "plant", legs: 0 }
    ]
    
    let livingThings = crossfilter(data)
    
    var n = livingThings.groupAll().reduceCount().value()
    echo "There are " & $n & " living things in my house."
    
    
    Run

Reply via email to