2019/day 2/index.js
/**
 *
 * @param {string} inputFile The source of the input file
 * @param {Function} cb A callback with the result intcode
 */
@param {string} inputFile The source of the input file
@param {Function} cb A callback with the result intcode
@param { string } inputFile The source of the input file @param { Function } cb A callback with the result intcode
function makeIntcodeFromFile (inputFile, replacements, cb) {
  if (typeof replacements === 'function') {
    cb = replacements
    replacements = null
  }
  fs.readFile(inputFile, 'utf8', (err, data) => {
    if (err) cb(err)
    data = data.split(',').map(n => parseInt(n, 10))
    if (replacements) {
      for (const replace in replacements) {
        data[replace] = replacements[replace]
      }
    }
    cb(null, makeIntcode(data))
  })
}
function makeIntcodeFromFile ( inputFile , replacements , cb ) { if ( typeof replacements === 'function' ) { cb = replacements replacements = null } fs . readFile ( inputFile , 'utf8' , ( err , data ) => { if ( err ) cb ( err ) data = data . split ( ',' ) . map ( n => parseInt ( n , 10 ) ) if ( replacements ) { for ( const replace in replacements ) { data [ replace ] = replacements [ replace ] } } cb ( null , makeIntcode ( data ) ) } ) }
@param {string} inputFile The source of the input file
 @param {Function} cb A callback with the result intcode
@param { string } inputFile The source of the input file @param { Function } cb A callback with the result intcode