Repository navigation
Birmingham | 26-JUL-SDC |Merve Reis | Sprint 1 | Analyse and Refactor #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mervereis
wants to merge
11
commits into
CodeYourFuture:main
Choose a base branch
from
mervereis:sprint1-analyse-and-refactor-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+162
−91
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
50c74a8
Refactor calculateSumAndProduct function for clarity and efficiency
mervereis a9341af
Update documentation for findCommonItems function to clarify time and…
mervereis 55a699b
Refactor hasPairWithSum function to improve time complexity and updat…
mervereis bf5629b
Refactor removeDuplicates function to improve time complexity and upd…
mervereis 7a56fcb
Refactor calculate_sum_and_product function for clarity and efficiency
mervereis 749da3a
Refactor find_common_items function to improve efficiency and update …
mervereis 78e3cec
Refactor has_pair_with_sum function to improve efficiency and update …
mervereis de7ed1e
Refactor remove_duplicates function to improve time complexity and up…
mervereis decfeab
Refactor removeDuplicates function to improve time complexity and sim…
mervereis 7b28f6d
Remove print statements and example usages from multiple functions fo…
mervereis 0aae0c9
Refactor findCommonItems function to improve time and space complexit…
mervereis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 30 additions & 9 deletions
39
Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| /** | ||
| * Finds common items between two arrays. | ||
| * | ||
| * Time Complexity: | ||
| * Space Complexity: | ||
| * Optimal Time Complexity: | ||
| * Time Complexity: O(n + m) | ||
| * Space Complexity: O(n + m) | ||
| * | ||
| * @param {Array} firstArray - First array to compare | ||
| * @param {Array} secondArray - Second array to compare | ||
| * @returns {Array} Array containing unique common items | ||
| */ | ||
| export const findCommonItems = (firstArray, secondArray) => [ | ||
| ...new Set(firstArray.filter((item) => secondArray.includes(item))), | ||
| ]; | ||
|
|
||
| export function findCommonItems(firstArray, secondArray) { | ||
| const firstSet = new Set(firstArray); | ||
| const secondSet = new Set(secondArray); | ||
|
|
||
| return [...firstSet.intersection(secondSet)]; | ||
| } |
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
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
36 changes: 12 additions & 24 deletions
36
Sprint-1/Python/calculate_sum_and_product/calculate_sum_and_product.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,19 @@ | ||
| from typing import Dict, List | ||
|
|
||
|
|
||
| def calculate_sum_and_product(input_numbers: List[int]) -> Dict[str, int]: | ||
| """ | ||
| Calculate the sum and product of integers in a list. | ||
|
|
||
| Note: the sum is every number added together | ||
| and the product is every number multiplied together | ||
| so for example: [2, 3, 5] would return | ||
| { | ||
| "sum": 10, // 2 + 3 + 5 | ||
| "product": 30 // 2 * 3 * 5 | ||
| } | ||
| Time Complexity: | ||
| Space Complexity: | ||
| Optimal time complexity: | ||
| """ | ||
| # Edge case: empty list | ||
| if not input_numbers: | ||
| return {"sum": 0, "product": 1} | ||
| total_sum = 0 | ||
| total_product = 1 | ||
|
|
||
| for number in input_numbers: | ||
| total_sum += number | ||
| total_product *= number | ||
|
|
||
| sum = 0 | ||
| for current_number in input_numbers: | ||
| sum += current_number | ||
| return {"sum": total_sum, "product": total_product} | ||
|
|
||
| product = 1 | ||
| for current_number in input_numbers: | ||
| product *= current_number | ||
|
|
||
| return {"sum": sum, "product": product} | ||
| """ | ||
| Time Complexity: O(n) | ||
| Space Complexity: O(1) | ||
| Optimal Time Complexity: O(n) | ||
| """ |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,22 @@ | ||
| from typing import List, TypeVar | ||
| def has_pair_with_sum(numbers, target_sum): | ||
|
|
||
| Number = TypeVar("Number", int, float) | ||
| seen = set() | ||
|
|
||
| for number in numbers: | ||
| complement = target_sum - number | ||
|
|
||
| def has_pair_with_sum(numbers: List[Number], target_sum: Number) -> bool: | ||
| """ | ||
| Find if there is a pair of numbers that sum to a target value. | ||
| if complement in seen: | ||
| return True | ||
|
|
||
| seen.add(number) | ||
|
|
||
| Time Complexity: | ||
| Space Complexity: | ||
| Optimal time complexity: | ||
| """ | ||
| for i in range(len(numbers)): | ||
| for j in range(i + 1, len(numbers)): | ||
| if numbers[i] + numbers[j] == target_sum: | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| """ | ||
| Find if there is a pair of numbers that sum to a target value. | ||
|
|
||
| Time Complexity: O(n²) | ||
| Space Complexity: O(1) | ||
| Optimal Time Complexity: O(n) | ||
| """ | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,21 @@ | ||
| from typing import List, Sequence, TypeVar | ||
| def remove_duplicates(values): | ||
|
|
||
| ItemType = TypeVar("ItemType") | ||
|
|
||
|
|
||
| def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]: | ||
| """ | ||
| Remove duplicate values from a sequence, preserving the order of the first occurrence of each value. | ||
|
|
||
| Time complexity: | ||
| Space complexity: | ||
| Optimal time complexity: | ||
| """ | ||
| unique_items = [] | ||
| seen = set() | ||
|
|
||
| for value in values: | ||
| is_duplicate = False | ||
| for existing in unique_items: | ||
| if value == existing: | ||
| is_duplicate = True | ||
| break | ||
| if not is_duplicate: | ||
| if value not in seen: | ||
| unique_items.append(value) | ||
| seen.add(value) | ||
|
|
||
| return unique_items | ||
|
|
||
|
|
||
| """ | ||
| Remove duplicate values from a sequence, | ||
| preserving the order of the first occurrence. | ||
|
|
||
| Time complexity: O(n²) | ||
| Space complexity: O(n) | ||
| Optimal time complexity: O(n) | ||
| """ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.