Reassign: Padowan to Jedi

December 13, 2015

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