Last Updated: February 25, 2016
·
1.739K
· dustinrjo

Simple Fiddle for scoping in coffeescript array loop

It can be difficult to follow variables throughout a for...in...do loop in Coffeescript, so I made this fiddle to test out the shortest syntax to loop and return conditionally only if a criteria is met.

a = [
    "bird",
    "cat",
    "moose"
]

testfunc = (b) ->
    e = ""
    for c in b
        do (c) ->
            if c is "bird"
                e = c
    return e

console.log testfunc(a)

http://jsfiddle.net/Ec245/2/

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside