-
Notifications
You must be signed in to change notification settings - Fork 8
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
Wrote grouped_anagrams method. #1
base: master
Are you sure you want to change the base?
Conversation
…sts to match changes from Matt.
…icated about Big-O notation and the most efficient solution.
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.
Nice work, you hit the learning goal of this exercise. Well done.
|
||
// Assert | ||
expect(answer.sort()).to.eql([1]); | ||
}); | ||
}); | ||
|
||
describe.skip("valid sudoku", function() { | ||
it("is not valid if a row has duplicate values", function() { |
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.
I'll add this to my set of tests
function grouped_anagrams(strings) { | ||
throw new Error("Method hasn't been implemented yet!"); | ||
// Time Complexity: O(n) where n is the length of the array passed in as the argument "strings" because each item in the array is visited once | ||
// Space Complexity: O(1) (***Chris, is this right? It takes 2 times the space of 'strings' which reduces to 1. Or is it O(n) because the space taken is is 2 x n where n is the length of the 'strings' array?***) |
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.
I would say O(n) because you are building a JavaScript object which scales based on the size of the array.
|
||
strings.forEach(str => { | ||
let tempStr = str.split('').sort().join(''); // alphabetize str | ||
anagrams[tempStr] ? anagrams[tempStr].push(str) : anagrams[tempStr] = [str]; |
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.
Good use of a ternary.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions