DEV Community

Cover image for Second Hacktoberfest Contribution
DerekJxy
DerekJxy

Posted on

Second Hacktoberfest Contribution

The Second Issue I found for the Release 0.2 was a JavaScript Program. It called "Helpful.js", "A collection of helpful JavaScript functions, started by TogaTech.org and built by the open-source community."

Issue

The issue I assigned for this program was "adding a new method that finds the average of an Array to the program." [Issue #16]
Issue description

My Solution

In order to solve this issue, the first step I took was try my best to go through the program and run the program on my local machine. After read through the code, I found out that this program using a package mocha that is similar to Angular. Therefore, I used the assignment that I finished with Angular as a reference to fix this issue. Finally, I added a new function and a test function to the program to achieve the goal of Issue #16.

    helpful.average = function(array) {
        if(array == null ) {
            return [];
        }
        let sum = 0;
        for(let i = 0; i < array.length; i++) {
            sum += array[i];
        }
        let average = sum / array.length ;
        return average;
    }
Enter fullscreen mode Exit fullscreen mode
    it(`${i}: average - Should calculate the average of an array`, function(){
            let expected = 2.75;
            let actual = helpful.average([1, 2, 4, 4]);
            assert.equal(expected, actual);
        });
Enter fullscreen mode Exit fullscreen mode

Through 5-7 of testings, I committed my changes to the repository that I cloned. Also, I made a Pull Request for my solution.
Surprsingly, the repository owner accepted my solution and merged it to the original Github Repository after a few days that I made my Pull Request!

My Feelings

To be honest, this contribution means a lot to me! This is the first time that my Pull Request that got merged to the original Github repository that outside of school. It means that the owner of the program agrees with my solution!
It encourages me to contribute more in the future!

Link to the Repo I worked with: [Helpful.js]

Top comments (1)

Collapse
 
kabir profile image
Kabir R.

We're so glad you enjoyed contributing to our repository!