I'm starting just now with CoffeeScript
CoffeeScript and I found out that I can't solve problems like looping and recursives with just one line. I would like to improve the code that I just wrote using built-in CoffeeScript
CoffeeScript helpers.
'use strict'
file_system = require 'fs'
Types = require './types'
Extract =
each_file: (index = 0) ->
length = @files.length
file = @files[index]
if index < length
Types.read file, @next.bind @
@each_file index + 1
next: (file) ->
@result.push file
if @result.length == @files.length
return @cb.clean.call @cb, @result
@each_file()
return
init: (files, cb) ->
@files = files
@cb = cb
@result = []
@each_file()
return
module.exports = Extract
I was studying coffee and I found out that I can't solve problems like looping and recursives with just one line. I would like to improve my code using this build on coffeescript
helpers.
The script speaks for itself; I'm doing a recursive function to send files to Types.read
, and I store the result in the result array.
Thanks.