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
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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#