Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Doesn't Recognize Syntactically Different Idiomatic 'Error First' Pattern on 'Make It Modular' #716

Closed
manavm1990 opened this issue Oct 15, 2020 · 1 comment

Comments

@manavm1990
Copy link

Below, kindly see My Solution and LMK what is the issue with this one in comparison to 'Official' Solution. They seem very similar. 😖

My Solution

'make-it-modular.js'

const filterFiles = require("./mymodule");

const [_, __, dir, ext] = process.argv;

filterFiles(dir, ext, (err, files) => {
  if (err) {
    return console.error(err);
  }

  return files.forEach((file) => {
    console.info(file);
  });
});

'mymodule.js'

const { readdir } = require("fs");
const { extname } = require("path");

module.exports = (dir, ext, cb) => {
  readdir(dir, (err, files) => {
    if (err) {
      return cb(err);
    }

    return cb(
      null,
      files.filter((file) => extname(file) === `.${ext}`)
    );
  });
};
✓

 Submission results match expected

 ✓

 Additional module file exports a single function

 ✓

 Additional module file exports a function that takes 3 arguments

 ✗

 Your additional module file [mymodule.js] does not appear to pass back an
 error received from fs.readdir(). Use the following idiomatic Node.js
 pattern inside your callback to fs.readdir(): if (err) return
 callback(err)

'Official' Solution

 Here's the official solution in case you want to compare notes:

─────────────────────────────────────────────────────────────────────────────
 _/usr/local/lib/node_modules/learnyounode/exercises/make_it_modular/soluti
 on/solution.js_ :


    'use strict'
    const filterFn = require('./solution_filter.js')
    const dir = process.argv[2]
    const filterStr = process.argv[3]

    filterFn(dir, filterStr, function (err, list) {
      if (err) {
        return console.error('There was an error:', err)
      }

      list.forEach(function (file) {
        console.log(file)
      })
    })

─────────────────────────────────────────────────────────────────────────────
 _/usr/local/lib/node_modules/learnyounode/exercises/make_it_modular/soluti
 on/solution_filter.js_ :


    'use strict'
    const fs = require('fs')
    const path = require('path')

    module.exports = function (dir, filterStr, callback) {
      fs.readdir(dir, function (err, list) {
        if (err) {
          return callback(err)
        }

        list = list.filter(function (file) {
          return path.extname(file) === '.' + filterStr
        })

        callback(null, list)
      })
    }
@manavm1990
Copy link
Author

manavm1990 commented Oct 15, 2020

Duplicate of 700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant