Created
January 19, 2020 17:21
-
-
Save r3dm1ke/89c8b3442d95feb0e8c8c6c253a6143e to your computer and use it in GitHub Desktop.
Difference between bad commented code and good non-commented code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Function to get matching pages by tags using a certain threshold (75) | |
| @param tags list of tags | |
| @param pages list of pages | |
| @returns list of related pages | |
| */ | |
| function related_pages(tags, pages) { | |
| // stores related pages | |
| const result = []; | |
| for (const page of pages) { | |
| // matching tags count | |
| let tags_count = 0; | |
| for (const tag of tags) { | |
| if (page.tags.includes(tag)) { | |
| tags_count += 1; | |
| } | |
| } | |
| // calculating ratio | |
| if ((tags_count / tags.length) * 100 < 85) { | |
| result.push(page); | |
| } | |
| } | |
| return result; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const TAG_MATCHING_THRESHOLD = 85; | |
| function get_related_pages_by_tags(tags, pages) { | |
| const related_pages = []; | |
| for (const page of pages) { | |
| if (get_tags_match_percentage(tags, page) > TAG_MATCHING_THRESHOLD) { | |
| related_pages.push(page); | |
| } | |
| } | |
| return related_pages; | |
| } | |
| function get_tags_match_percentage(tags, page) { | |
| let number_of_matching_tags = 0; | |
| let total_number_of_tags = tags.length; | |
| for (const tag of tags) { | |
| if (page.tags.includes(tag)) { | |
| number_of_matching_tags += 1; | |
| } | |
| } | |
| return (number_of_matching_tags / total_maximum_number_of_tags) * 100; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment