...use a functional library, like lodash, underscore, or ramda in every project?
...find this code hard to follow?
callback( _.flatten(
_.compact( _.flatten(myArray) ).map(function(item){
return JSON.stringify(
Math.pow( parseInt(item) * 100, 2 )
).replace(/0+/, '');
})
));
...not want to learn a whole new language, throwing away most of your JavaScript skills?
callback( _.flatten(
_.compact( _.flatten(myArray) ).map(function(item){
return JSON.stringify(
Math.pow( parseInt(item) * 100, 2 )
).replace(/0+/, '');
})
));
my-array
|> flatten
|> compact
|> map ->
it
|> parse-int
|> (* 100)
|> (** 2)
|> JSON.stringify
|> (.replace /0+/, '')
|> flatten
|> callback
Much more obvious control flow
my-array
|> flatten
|> compact
|> map ->
it
|> parse-int
|> (* 100)
|> (** 2)
|> JSON.stringify
|> (.replace /0+/, '')
|> flatten
|> callback
A functional standard library!
my-array
|> flatten
|> compact
|> map ->
it
|> parse-int
|> (* 100)
|> (** 2)
|> JSON.stringify
|> (.replace /0+/, '')
|> flatten
|> callback
flatten, compact, and many, many other useful functions have been pulled from Haskell
Flexible learning curve
callback( flatten(
compact( flatten(myArray) ).map( (item) ->
return JSON.stringify(
Math.pow( parseInt(item) * 100, 2 )
).replace(/0+/, '');
)
));
unlike ClojureScript, you don't have to start from scratch and learn a whole new language before you can be productive
callback( _.flatten(
_.compact( _.flatten(myArray) ).map(function(item){
return JSON.stringify(
Math.pow( parseInt(item) * 100, 2 )
).replace(/0+/, '');
})
));
learnxinyminutes.com/docs/livescript