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

  • SEARCH
  • Home
  • 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 8084689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:52:18+00:00 2026-06-05T17:52:18+00:00

Background : I’m trying to convert some JavaScript code which uses the the Crossfilter

  • 0

Background: I’m trying to convert some JavaScript code which uses the the Crossfilter library with D3.js data visualization library into CoffeeScript.

What is the best way to convert a JavaScript forEach loop/function into CoffeeScript?

Here’s the JavaScript code:

// A little coercion, since the CSV is untyped.
flights.forEach(function(d, i) {
    d.index = i;
    d.date = parseDate(d.date);
    d.delay = +d.delay;
    d.distance = +d.distance;
});

Can CoffeeScript do an in-line function inside a loop? Right now I’m guess I need it broken out into a function and loop:

coerce = (d) ->
     d.index    = 1
     d.date     = parseDate(d.date)
     d.delay    = +d.delay
     d.distance = +d.distance

coerce(flights) for d in flights
  • 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-05T17:52:19+00:00Added an answer on June 5, 2026 at 5:52 pm

    use a comprehension

    for d, i in flights
      console.log d, i
    

    The code above translates to

    var d, i, _i, _len;
    
    for (i = _i = 0, _len = flights.length; _i < _len; i = ++_i) {
      d = flights[i];
      console.log(d, i);
    }
    

    so you can see d and i are what you want them to be.

    Go here and search for “forEach” for some examples.

    Finally, look at the first comment for some more useful info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I am writing a class library assembly in C# .NET 3.5 which is
Background: I am trying to add data to a SQL DB with C#. I
Background: I am a beginner javascript developer who is trying to understand and learn
Background Hi All, I'm trying to use Boost::MPI, at the moment I'm just trying
Background: I am developing an app which sends an SMS to users after registration
BACKGROUND I'm using VS 2010 on a machine where I installed .Net 4.5 which
Background I am writing code in VS 2010, .NET 4, C#. Also, in case
Background A lot of work has gone into optimizing database design, especially in the
Background I have a ror application which is continuously recording and showing on a
Background info I am trying to upgrade a custom CMS to support the HTML5

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.