Skip to main content
added 462 characters in body
Source Link
Jonah
  • 4.4k
  • 14
  • 22

Both the idea and implementation look sound to me. As a nitpick, you might consider using a reduce on the opts, giving you a one liner. Also, I believe the hasOwnProperty test is superfluous here

Untested reduce version

Note that, per Joseph's suggestion, which I agree with, this creates the AudioOutConfig object for you, rather than requiring it as a parameter:

function config(opts) {
  return Object.keys(opts).reduce((audio, opt) => {
    const methodName = `set${opt.charAt(0).toUpperCase() + opt.slice(1)}`
    return audio[methodName] ?  audio[methodName](opts[opt]) : audio
  }, new AudioOutConfig())
}

Both the idea and implementation look sound to me. As a nitpick, you might consider using a reduce on the opts, giving you a one liner. Also, I believe the hasOwnProperty test is superfluous here

Both the idea and implementation look sound to me. As a nitpick, you might consider using a reduce on the opts, giving you a one liner. Also, I believe the hasOwnProperty test is superfluous here

Untested reduce version

Note that, per Joseph's suggestion, which I agree with, this creates the AudioOutConfig object for you, rather than requiring it as a parameter:

function config(opts) {
  return Object.keys(opts).reduce((audio, opt) => {
    const methodName = `set${opt.charAt(0).toUpperCase() + opt.slice(1)}`
    return audio[methodName] ?  audio[methodName](opts[opt]) : audio
  }, new AudioOutConfig())
}
Source Link
Jonah
  • 4.4k
  • 14
  • 22

Both the idea and implementation look sound to me. As a nitpick, you might consider using a reduce on the opts, giving you a one liner. Also, I believe the hasOwnProperty test is superfluous here