- I have asked for this issue, and was assigned it
- I have properly filled the "Details" section above
- I didn't modify any test case
- I have implemented the function and all its tests pass
- I have added a new test case for someone to implement
- I have created an issue for my new test case
- I've
the repository (or not, all up to you) - And more importantly, I've had fun!
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-567I 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:
- Go through the array of arguments for (let i=0; i<args.length;i++)
- For each argument go through the rest of the array for (let j=i+1; j<args.length;j++)
- If found the same argument, return true if (args[i] == args[j]) return true;
- 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;
};
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