generator-hackerrank
v1.1.0
Published
Yeoman generator for HackerRank challenges
Downloads
24
Readme
generator-hackerrank
Generate a Javascript template & unit tests for solving another one of those /r/hackerrank challenges
Installation
First, install Yeoman and generator-hackerrank using npm (we assume you have pre-installed node.js).
npm install -g yo
npm install -g generator-hackerrank
Then generate your new project:
yo hackerrank
This will ask for the task scope and name, along with some other options, and produce the following result:
Main file
// {scope}/{task}.js
const solve = (n) => {
// Put your solution here
return n;
};
module.exports = { solve };
Unit tests
// {scope}/{task}.test.js
const { solve } = require('./task');
describe('Sample Task', () => {
const examples = [
{
query: [1, 2, 3],
answer: 5,
}
];
examples.forEach(({ query, answer }, i) => {
it(`should solve example ${i}`, () => {
expect(solve(query)).toEqual(answer);
});
});
});
License
MIT © Wain-PC