0

This coffeescript...

"""
#{@display_event_small(event) for event in data.top_events}
"""

outputs commas between each of the elements in data.top_events. I need to have them concatenate without commas in between. Of course, I could use a more customized loop, but I would imagine CoffeeScript has a nicer way of changing this behavior.

Let me know if I need to clarify. Thanks.

1 Answer 1

6

The loop expression results in an array so you could explicitly join the elements with an empty string delimiter:

"""
#{(@display_event_small(event) for event in data.top_events).join('')}
"""

There's no special formatting options for "#{}", CoffeeScript just turns it inside out and hands it off to JavaScript's +. An interpolated string like "a #{b} c" becomes

"a " + b + " c"

when compiled to JavaScript and JavaScript is inserting the commas when it stringifies your array.

Sign up to request clarification or add additional context in comments.

1 Comment

It's the contrast between [1,2,3].toString() and [1,2,3].join('').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.