Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:18:33+00:00 2026-06-10T11:18:33+00:00

Is it possible to filter a crossfilter dataset which has an array as the

  • 0

Is it possible to filter a crossfilter dataset which has an array as the value?

For example, say I have the following dataset:

var data = [
  {
    bookname: "the joy of clojure",
    authors: ["Michael Fogus", "Chris Houser"],
    tags: ["clojure", "lisp"]
  },
  {
    bookname: "Eloquent Ruby",
    authors: ["Russ Olsen"],
    tags: ["ruby"]
  },
  {
    bookname: "Design Patterns in Ruby",
    authors: ["Russ Olsen"],
    tags: ["design patterns", "ruby"]
  }
];

Is there an easy way to access the books which are tagged by an particular tag? And also the books which have a particular author? The way I understand how to use crossfilter so far has me doing something like this:

var filtered_data = crossfilter(data);
var tags = filtered_data.dimension(function(d) {return d.tags});
var tag = tags.group();

And then when I access the grouping (like so):

tag.all()

I get this:

[{key: ["clojure", "lisp"], value: 1}, 
 {key: ["design patterns", "ruby"], value: 1}, 
 {key: ["ruby"], value: 1}]

When I would rather have this:

[{key: "ruby", value: 2}, 
 {key: "clojure", value: 1}, 
 {key: "lisp", value: 1},
 {key: "design patterns", value: 1}]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:18:34+00:00Added an answer on June 10, 2026 at 11:18 am

    I’ve added comments to the code below. Big picture: use reduce function.

    var data = ...
    var filtered_data = crossfilter(data);
    var tags = filtered_data.dimension(function(d) {return d.tags});
    
    tags.groupAll().reduce(reduceAdd, reduceRemove, reduceInitial).value()
    

    Notice how I’ve used groupAll() instead of group() b/c we want our reduce functions (defined below) to operate on one group rather than 3 groups.

    Now the reduce functions should look like this:

    /*
     v is the row in the dataset
    
     p is {} for the first execution (passed from reduceInitial). 
     For every subsequent execution it is the value returned from reduceAdd of the prev row
    */
    function reduceAdd(p, v) {
      v.tags.forEach (function(val, idx) {
         p[val] = (p[val] || 0) + 1; //increment counts
      });
      return p;
    }
    
    function reduceRemove(p, v) {
       //omitted. not useful for demonstration
    }
    
    function reduceInitial() {
      /* this is how our reduce function is seeded. similar to how inject or fold 
       works in functional languages. this map will contain the final counts 
       by the time we are done reducing our entire data set.*/
      return {};  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to filter out subsets of the data that have small numbers
Is it possible to combine Underscore's filter and map? I currently have two separate
Is it possible to make the groupby filter order in descending order? I have
i was wondering if it was possible to filter which action is invoked based
I have a varchar column that has generally has a decimal value, but some
Is it possible to filter on a particular joined-subclass in NHibernate? For example, I
Is it possible to filter HTTPs traffic? For example via a TDI filter? Or
Possible Duplicate: Gallery with folder filter I'm using following code to open a gallery
Is it possible to filter a named query in a reporting services data source
I have the following scenario: I have a content type called 'Product' in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.