Introduction
Hacktoberfest is the biggest festival for opensource programmer which takes place in October every year. As a first-timer, I felt very excited to be a part of this year Hacktoberfest. Therefore, I would like to write about my experience after making the first PR.
Difficulties
Well, since this is my first time, I was kind of overwhelmed and strange with the number of projects there are on Github. So, I was looking for something which is:
Not too simple
There are plenty of repos on Github that only ask me to add my name for my first PR. However, that is not what I was looking for since I don't want to put so little effort once I start working.
Not too overwhelming
As a first-timer, due to the lack of experience, I don't want to put myself in a difficult situation which I cannot finish what I start.
Looking for the right repo to work on seems to be the first difficulties that I encountered.
The repo I have chosen
Thanks to the recommendation of a classmate, I found a perfect repo for me to work on which is algo_ds_101. This is a collection of algorithms and data structures code written in different programming languages.
Issue that I worked on
This repo is perfect for me to work on since it's not too complicated and I don't have to put so little effort in the problem.
I started to make approach to issue 842 which asked to write an algorithm that counts the number of divisible pair in a array.
What did I need to do to prepare for the fix?
There are not so much requirements for the issue. I only need to write a block of code in JavaScript that can count the number of divisible pair in an array.
Let me explain a little bit about the requirement:
if there is an array arr[] = {1, 2, 3}
then the two pairs are (1, 2) and (1, 3).
My pull request
See, the requirement is not so hard. I believe with the basic knowledge of programming, any of us could solve this problem easily. You can have a look at my pull request at my first full request.
for (let i = 0; i < n; i++) // iterate through the array from i = 0
{
for (let j = i + 1; j < n; j++) // iterate through the array start from the element next to arr[i]
{
if (
(arr[i] % arr[j] == 0)
|| (arr[j] % arr[i] == 0)
)
{
count++; // increase count by 1, if it is under the condition
}
}
}
return count;
}
let arr = [2,3,5,8,9];
console.log(DivisiblePairCount(arr, arr.length));
- First I iterate the array from
i = 0
. - I put a nested loop which starts from
j = i + 1
in the previous loop. *Therefore, whenever an element at j is divided by an element at i or vice versa,count
will increase by 1.
Conclusion
Well, my first PR is as simple as it is. But it is a huge encouragement since it gives me a sense of achievement so that I could keep going until the end of Hacktoberfest.
Top comments (1)
Great!!