Skip to content

ITP_GLASGOW_APR | HANNA_MYKYTIUK | MODULE__DATA_\GROUPS | SPRINT_2 #492

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HannaOdud
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@HannaOdud HannaOdud added the Needs Review Participant to add when requesting review label Apr 10, 2025
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unrelated files when you request a code review.

Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left you some comments. Feel free to mark this as "Complete" after you have made the changes accordingly.

Some of my comments are just information. No action needed.

Comment on lines +45 to +48
it("in case of invalid parametr function contains should throw an error", () => {
expect(contains( [1,2,3], 'property')).toEqual(false);
expect(contains( "test", 'property')).toEqual(false);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st Issue:
Did you run this test script? I don't think your current implementation can pass this test.

Array is a kind of objects in JavaScript where its indexes are treated as key. So
contains([4, 4, 4], '0') or contains([4, 4, 4], 1) would return true.
Object.hasOwn("ABC", 1) would also return true.

If you want to reject any type of value that is not an object, you will need to explicitly write code to check. (You can try asking ChatGPT how to properly check if a value is an object in JS)

2nd Issue:
Your function is not throwing any error. If you modify your function to throw error, you would need to prepare the test code in the following manner:

    it("in case of invalid parameter function contains should throw an error", () => {
      // Need to wrap the function call in a function
      expect( () => contains([1,2,3], 'property') ).toThrow();
      expect( () => contains("test", 'property') ).toThrow();
    });  

Comment on lines +11 to +17
let value = '';
for(let i = 1; i<array.length; i++){
value += array[i];
if (i != array.length - 1){
value += '=';
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also write this as array.slice(1).join("="). Return an array without the first element and then join the elements using '='.

value += '=';
}
}
queryParams[array[0]] = value;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that in real querystring, both key and value are percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), you should call a function to decode it.
May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?

function tally() {}
function tally(array) {
try {
if (typeof(array) == 'string'){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to check if a value is an array. (Ask ChatGPT)
You can just return false or throw an error if array is NOT an array, instead of just check for "string". There are other types of value that is not array.

Comment on lines +7 to +22
let copy = [];
for (let i=0; i<array.length; i++){
if (copy.indexOf(array[i]) === -1) {
copy.push(array[i]);
}
}
let object = {};
for (let i=0; i < copy.length; i++){
let count = 0;
for (let j=0; j < array.length; j++){
if (array[j] == copy[i]){
count = count + 1;
}
}
object[copy[i]] = count;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you try implement the following approach (which is more efficient by using object as a lookup table):

  let object = {};
  for each element, ele, in the arrays
    if object[ele] is undefined
      set object[ele] to 1
    else 
      increment object[ele] by 1

Comment on lines +46 to +48
it("Given an invalid input it should throw an error", () => {
expect(tally('string')).toEqual(false);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your function is not throwing any error when the parameter is not an array (the description of the test is not quite correct).

noPunctuation = noPunctuation.toLowerCase();
const words = noPunctuation.split(" ");
for(i=0; i<words.length; i++){
if (Object.hasOwn(countedWords, words[i])){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also write if (countWords[words[i]]), which can be interpreted as "if countWords[words[i]] has a value" (and we know that it cannot be zero).

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants