Skip to main content
edited tags; edited title
Link
200_success
  • 144.1k
  • 22
  • 188
  • 473

Improving coffee code Operating on a list of files using recursion

Notice removed Draw attention by Amanda Ferrari
Bounty Ended with SirPython's answer chosen by Amanda Ferrari
Notice added Draw attention by Amanda Ferrari
Bounty Started worth 100 reputation by Amanda Ferrari
More consice description, add node tag since it's being used.
Source Link
ferada
  • 11.1k
  • 25
  • 63

I'm starting just now with CoffeeScriptCoffeeScript 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 CoffeeScriptCoffeeScript 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.

I'm starting just now with CoffeeScript and I would like to improve the code that I just wrote using built-in 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.

I'm starting just now with 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 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

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.

edited body
Source Link
BCdotWEB
  • 11.3k
  • 2
  • 27
  • 45

I'm starting just now with CoffeeScript and I would like to improve the code that I just wrote using build inbuilt-in 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 Scriptscript 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.

I'm starting just now with CoffeeScript and I would like to improve the code that I just wrote using build in 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.

I'm starting just now with CoffeeScript and I would like to improve the code that I just wrote using built-in 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.

improved grammar
Source Link
TheCoffeeCup
  • 9.4k
  • 4
  • 36
  • 96
Loading
Source Link
Loading