Skip to content

Commit 1e2d54a

Browse files
committed
reviewer feedback implemented
1 parent aa214a5 commit 1e2d54a

File tree

8 files changed

+42
-47
lines changed

8 files changed

+42
-47
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
node_modules
33
.venv
44
__pycache__
5+
package-lock.json
6+
Sprint-1/JavaScript/package-lock.json

Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* "product": 30 // 2 * 3 * 5
1010
* }
1111
*
12-
* Time Complexity: O(N) 2 for loops for loops are 0
13-
* Space Complexity: O(1) 2 variables
12+
* Time Complexity: O(N) the previous two loops are swapped into one loop
13+
* Space Complexity: O(1) 2 variables - sum and product
1414
* Optimal Time Complexity: O(N)
1515
*
1616
* @param {Array<number>} numbers - Numbers to process

Sprint-1/JavaScript/findCommonItems/findCommonItems.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
export const findCommonItems = (firstArray, secondArray) => {
1717
// ...new Set(firstArray.filter((item) => secondArray.includes(item))),
1818
const dictToCheck = {};
19-
const doubled = [];
19+
const common = [];
2020

2121
for (const item of firstArray) {
2222
dictToCheck[item] = true;
@@ -28,5 +28,5 @@ export const findCommonItems = (firstArray, secondArray) => {
2828
dictToCheck[item] = false;
2929
}
3030
}
31-
return doubled;
31+
return common;
3232
};

Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,26 @@
1010
* @param {number} target - Target sum to find
1111
* @returns {boolean} True if pair exists, false otherwise
1212
*/
13-
// export function hasPairWithSum(numbers, target) {
14-
// we are now making a cake from cake slices
15-
// numbers are now slices of cake and target is a a number of slices taht makes a whole cake
1613

17-
export function hasPairWithSum(slices, targetWholeCake) {
14+
export function hasPairWithSum(numbers, target) {
1815
// for (let i = 0; i < numbers.length; i++) {
1916
// for (let j = i + 1; j < numbers.length; j++) {
2017
// if (numbers[i] + numbers[j] === target) {
2118
// return true;
2219
// }
2320
// }
2421
// }
25-
const inventoryOfSlices = {};
2622

27-
for (const slice of slices) {
28-
const missingPieces = targetWholeCake - slice;
23+
const inventory = {};
2924

30-
if (inventoryOfSlices[missingPieces]) {
25+
for (const num of numbers) {
26+
const needed = target - num;
27+
28+
if (inventory[needed]) {
3129
return true;
3230
}
3331

34-
inventoryOfSlices[slice] = true; // add slice
32+
inventory[num] = true;
3533
}
3634
return false;
3735
}

Sprint-1/JavaScript/package-lock.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

Sprint-1/Python/find_common_items/find_common_items.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def find_common_items(
2020
# common_items.append(i)
2121
# return common_items
2222

23-
dictToCheck = {}
23+
dict_to_check = {}
2424

2525
for item in first_sequence:
26-
dictToCheck[item] = True
26+
dict_to_check[item] = True
2727

28-
for item in second_sequence:
29-
if item in dictToCheck:
30-
common_items.append(item)
31-
dictToCheck.pop(item)
28+
for item in second_sequence:
29+
if item in dict_to_check:
30+
common_items.append(item)
31+
dict_to_check.pop(item)
3232

3333
return common_items
3434

Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@ def has_pair_with_sum(numbers: List[Number], target_sum: Number) -> bool:
1111
Space Complexity:O(N)
1212
Optimal time complexity:O(N)
1313
"""
14-
for i in range(len(numbers)):
15-
for j in range(i + 1, len(numbers)):
16-
if numbers[i] + numbers[j] == target_sum:
17-
return True
18-
return False
19-
# // i am using my cake exqmple from js
20-
inventory_of_slices = {}
21-
22-
for slice in numbers:
23-
missing_piece = target_sum - slice
24-
if missing_piece in inventory_of_slices:
25-
return True
14+
# for i in range(len(numbers)):
15+
# for j in range(i + 1, len(numbers)):
16+
# if numbers[i] + numbers[j] == target_sum:
17+
# return True
18+
# return False
19+
# using my cake exqmple from js
20+
# inventory_of_slices = {}
21+
22+
# for slice in numbers:
23+
# missing_piece = target_sum - slice
24+
# if missing_piece in inventory_of_slices:
25+
# return True
2626

27-
inventory_of_slices[slice] = True
27+
# inventory_of_slices[slice] = True
28+
inventory = {}
29+
30+
for number in numbers:
31+
missing = target_sum - number
32+
if missing in inventory:
33+
return True
2834

35+
inventory[number] = True
2936
return False

Sprint-1/Python/remove_duplicates/remove_duplicates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]:
2525
# return unique_items
2626

2727

28-
itemsWeChecked = {}
28+
items_we_checked = {}
2929
for item in values:
30-
if item not in itemsWeChecked:
30+
if item not in items_we_checked:
3131
unique_items.append(item)
32-
itemsWeChecked[item] = True
32+
items_we_checked[item] = True
3333

3434
return unique_items

0 commit comments

Comments
 (0)