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)
Written by Dustin Johnson
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#