Tuesday 9 October 2018

Hacktoberfest First Pull Request

I contributed to Hacktoberfest game. Here is the list of actions that must be done to take part in the game:

  •  I have asked for this issue, and was assigned it
  •  I have properly filled the "Details" section above arrow_up
  •  I didn't modify any test case red_circle
  •  I have implemented the function and all its tests pass white_check_mark
  •  I have added a new test case for someone to implement new
  •  I have created an issue for my new test case speak_no_evil
  •  I've star the repository (or not, all up to you)
  •  And more importantly, I've had fun! beer

To sum up, you need to solve a problem and to create a new problem that someone else will solve. The idea is that there are always available problems and everyone can start contributing to public repositories.

The Problem I solved

issue-527 pull-567

I wrote a function that takes unknown number of arguments and returns true if it contains any duplicate argument values. Otherwise, returns false (if all arguments are unique).

The algorithm is very simple:

  1. Go through the array of arguments for (let i=0; i<args.length;i++)
  2. For each argument go through the rest of the array for (let j=i+1; j<args.length;j++)
  3. If found the same argument, return true if (args[i] == args[j]) return true;
  4. If did not find any duplicates, return false return false;
Full code:

export const duplicatedArgs = (...args) => {
for (let i = 0; i < args.length; i++)
for (let j = i + 1; j < args.length; j++)
if (args[i] == args[j])
return true;
return false;
};

Problem I suggested

I suggested to write a power function. It is recommended that this function
works faster than O(n).
Here are tests for power():

describe('power', () => {
it('returns 125 for base 5 and power 3', () => {
expect(power(5, 3)).toEqual(125);
});

it('returns -125 for base -5 and power 3', () => {
expect(power(-5, 3)).toEqual(-125);
});

it('returns 1 for base 5 and power 0', () => {
expect(power(5, 0)).toEqual(1);
});

it('returns 5 for base 5 and power 1', () => {
expect(power(5, 1)).toEqual(5);
});

it('returns 1048576 for base 2 and power 20', () => {
expect(power(2, 20)).toEqual(1048576);
});
});

I recommend everyone to take part in this game, because it suits for your
first pull request on Hacktoberfest and it's not hard.
You can also use this game if you need help with some functions: just create
an issue with function description and someone will write it.😊

No comments:

Post a Comment