With the coming of November 1st, we had our third assignment -- Release 0.3 in OSD600. In this release 0.3, there are 3 different requirements. And the first one is about External Project Contribution.
For this external project contribution, I selected a repository that I worked with in Release 0.2. It called help.js.
This time, I worked at the issue about adding a testing method for objects. "We should have a method that finds the difference of two objects (any keys that are present in the second object are removed from the first)".
Procedure
Due to I forked this repository to my Giuhub account for my Release 0.2. I just need to pull all the new commits that the origin repository made recently with the command git pull origin main
. And then I started to add a new test function based on the issue.
At the beginning, I got stuck at "How can I get the keys from an object?". Therefore, I googled the solution from StackOverFlow.
There are some tips and ideas helped me to get the keys from an object. I used the method Object.keys()
and store it to an array
.
let array1 = Object.keys(object1);
And then I just used for loop to figure out whether there are some keys that present in the first object and the second object at the same time. If so, I just need to remove them from the first object. However, there was one more issue comes up at that timing -- "How do I remove those keys from the first object?" So, I searched the recommend ways on google again. And I found that I can use the word delete
to do that.
delete object1[array1[i]];
This code allows me to delete the keys in an object. And then I just add some test logic to the test.js
.
While I testing my code, I realized that my code would delete the keys from an object permanently. And I don't think that's a good practice for any programmer. Therefore, I tried to add a temporary object
to my function, and let the temporary object equals to the first input object. Then I could delete keys from the temporary object so that it will not affect the original first input object.
Surprisingly, this logic didn't work as I expected. It does delete keys from the temporary object, but it also deletes keys from the first input object! So, I just use an object that with same keys values again and again:
After I made the tests run successfully, I read through the testing code in the program again. And I found out that I was using a different format, which is a bad practice when you are trying to help improve a program that you didn't make it. So, I just audit my code with the same format as they did.
My feelings
Honestly, this is a more challenged issue for me. First of all, I don't familiar with working on object in JavaScript. Second of all, I don't have that much experience with contributing on Github. Last but no least, I messed up the coding procedure at the beginning which is a really bad practice. I should read through the code before I do any coding stuff.
Anyway, this is a helpful project for me. I learned how to get all the keys from an object and how to delete them. Also, I have more experience to contribute on Github!
Lind to the Repo I worked: [Helpful.js]
Top comments (0)