Reassign: Padowan to Jedi

3293 days ago, 0 views.

Smelly Code

data = this.appendAnalyticsData(data)
data = this.appendSubmissionData(data)
data = this.appendAdditionalInputs(data)
data = this.pruneObject(data)

Nested Functions

data = this.pruneObject(
  this.appendAdditionalInputs(
    this.appendSubmissionData(
      this.appendAnalyticsData(data)
    )
  )
)

forEach

var funcs = [
  this.appendAnalyticsData,
  this.appendSubmissionData,
  this.appendAdditionalInputs,
  this.pruneObject
]

funcs.forEach(function (func) {
  data = func(data)
})

Reduce

var funcs = [
  this.appendAnalyticsData,
  this.appendSubmissionData,
  this.appendAdditionalInputs,
  this.pruneObject
]

data = funcs.reduce(function (memo, func) {
  return func(memo)
}, data)

Flow

data = _.flow(
  this.appendAnalyticsData,
  this.appendSubmissionData,
  this.appendAdditionalInputs,
  this.pruneObject
)(data)

Bibliography

Kiko Beats

Kiko Beats