-
Notifications
You must be signed in to change notification settings - Fork 101
Added another method to 2sum Problem #60
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
Merged
ignacio-chiazzo
merged 2 commits into
ignacio-chiazzo:master
from
TemitopeAgbaje:Temitope
Oct 8, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,11 +1,19 @@ | ||
const assert = require('assert'); | ||
const twoSum = require('../../LeetcodeProblems/Algorithms/2Sum').twoSum; | ||
const assert = require("assert"); | ||
const twoSum = require("../../LeetcodeProblems/Algorithms/2Sum").twoSum; | ||
const twoSum2 = require("../../LeetcodeProblems/Algorithms/2Sum").twoSum2; | ||
|
||
var test = function () { | ||
assert.deepEqual([0,1], twoSum([2,7,11,15], 9)); | ||
assert.deepEqual([1,2], twoSum([3,2,4], 6)); | ||
assert.deepEqual([0,1], twoSum([3,3], 6)); | ||
} | ||
}; | ||
|
||
var test2 = function () { | ||
assert.deepEqual([0,1], twoSum2([2,7,11,15], 9)); | ||
assert.deepEqual([1,2], twoSum2([3,2,4], 6)); | ||
assert.deepEqual([0,1], twoSum2([3,3], 6)); | ||
}; | ||
|
||
module.exports.test = test; | ||
module.exports.test2 = test2; | ||
|
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,10 +1,10 @@ | ||
const assert = require('assert'); | ||
const threeSumClosest = require('../../LeetcodeProblems/Algorithms/3SumClosest').threeSumClosest; | ||
const assert = require("assert"); | ||
const threeSumClosest = | ||
require("../../LeetcodeProblems/Algorithms/3SumClosest").threeSumClosest; | ||
|
||
var test = function () { | ||
assert.equal(2, threeSumClosest([-1, 2 , 1, -4], 1)); | ||
assert.equal(2, threeSumClosest([-1, 2, 1, -4], 1)); | ||
assert.equal(0, threeSumClosest([0, 0, 0], 1)); | ||
|
||
} | ||
}; | ||
|
||
module.exports.test = test; |
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,22 +1,19 @@ | ||
const assert = require('assert'); | ||
const threeSum = require('../../LeetcodeProblems/Algorithms/3Sum').threeSum; | ||
const assert = require("assert"); | ||
const threeSum = require("../../LeetcodeProblems/Algorithms/3Sum").threeSum; | ||
|
||
var test = function () { | ||
assert.deepEqual(threeSum([]), []); | ||
assert.deepEqual(threeSum([0]), []); | ||
assert.deepEqual(threeSum([0, 0]), []); | ||
assert.deepEqual(threeSum([0, 0, 0]), [[0, 0, 0]]); | ||
assert.deepEqual( | ||
threeSum([0, 0, 0]), | ||
threeSum([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), | ||
[[0, 0, 0]] | ||
); | ||
assert.deepEqual( | ||
threeSum([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), | ||
[[0, 0, 0]] | ||
); | ||
assert.deepEqual( | ||
threeSum([-1, 0, 1, 2, -1, -4]), | ||
[ [ -1, 2, -1 ], [ 0, 1, -1 ] ] | ||
); | ||
} | ||
assert.deepEqual(threeSum([-1, 0, 1, 2, -1, -4]), [ | ||
[-1, 2, -1], | ||
[0, 1, -1], | ||
]); | ||
}; | ||
|
||
module.exports.test = test; |
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
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,38 +1,47 @@ | ||
const fs = require('fs'); | ||
/* eslint-disable no-useless-escape */ | ||
/* eslint-disable no-undef */ | ||
const fs = require("fs"); | ||
|
||
const TESTS_FOLDER = './LeetcodeProblemsTests/Algorithms/'; | ||
const TESTS_FOLDER = "./LeetcodeProblemsTests/Algorithms/"; | ||
const REGEX_PATTERN_HIDDEN_FILES = /(^|\/)\.[^\/\.]/g; | ||
|
||
var test_all = async function() { | ||
var test_all = async function () { | ||
try { | ||
const problems = await loadProblems(); | ||
for(i in problems) { | ||
for (i in problems) { | ||
console.log("Solving: " + problems[i]); | ||
const problem = require(TESTS_FOLDER + problems[i]); | ||
|
||
if (typeof(problem.test) !=='undefined') { | ||
if (typeof problem.test !== "undefined") { | ||
problem.test(); | ||
console.log("✅ Tests for " + problems[i] + " run successfully \n"); | ||
} else { | ||
console.warn(problem, "🔴 The problem " + problems[i] + " doesn't have a test method implemented.\n"); | ||
} | ||
console.warn( | ||
problem, | ||
"🔴 The problem " + | ||
problems[i] + | ||
" doesn't have a test method implemented.\n" | ||
); | ||
} | ||
} | ||
} catch (error) { | ||
throw new Error(error); | ||
} | ||
} | ||
}; | ||
|
||
var loadProblems = () => { | ||
return new Promise(function (resolve, reject) { | ||
fs.readdir(TESTS_FOLDER, (error, files) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
problems = files.filter(item => !(REGEX_PATTERN_HIDDEN_FILES).test(item)); | ||
problems = files.filter( | ||
(item) => !REGEX_PATTERN_HIDDEN_FILES.test(item) | ||
); | ||
resolve(problems); | ||
} | ||
}) | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
test_all(); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you encapsulate the new solution into a new method named
twoSum2
?There are other examples in other files like
CoinChange
https://github.com/ignacio-chiazzo/Algorithms-Leetcode-Javascript/blob/08563058f7e93ce1688956cc26d5dc2a98b36d1a/LeetcodeProblems/Algorithms/Coin_Change.js.Also, could you run the tests for both functions
twoSum
andtwoSum2
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright.. i would fix that