#How to read this in english?

36 messages · Page 1 of 1 (latest)

wide shoal
#

Is it okay to ask this?

    if (!isValid) {
      menuFilter = menuFilter.filter(f => ![4,5,7,8].includes(f));
    }

How do you read this in English? I always get confused with the order/inverse.
If it's not valid, then iterate through menuFilter[], but the right hand part beyond the => is confusing.

obtuse dock
#

If property is not valid, strips values 4,5,7,8 from menuFilter

crimson bane
#

If that's not valid, 4,5,7,8 are excuded from menuFilter.

Moving this part to a function with proper naming can help you to maintain it.
Creating a unit test is the best solution to test your logic: you know the input and the output.

wide shoal
#

What is the psuedo algorithm? Like includes is iterating the array [4,5,7,8]?

#

I have to break this down, I know includes true or false through array.

sterile quail
#

If property is not valid keep only the elements not included in 4, 5, 7, 8

#

If this is real code, you should really define constants instead of using magic numbers, and add comments explaining why you exclude those values

wide shoal
#

What makes this hard is the senior dev used a md array.

#
    //Status  Manual      Automated
    let items = [
      [[1,2], [1,2],      [1,2]],       //Waiting on Data
      [[3],   [1,2,3],    []],          //Ready for Agent
      [[4],   [1,4,6],    []],          //Waiting on Agent
      [[5],   [1,2,4,6],  [1,2,4,6]],   //Ready to Search

      [[11],  [4],        [4]],         //Waiting on Copies
      [[6],   [5],        [5]],         //Ready for Review
      [[8],   [7],        [7]],         //Ready for Release
      [[10],  [8],        [8]],         //Completed
      [[99],  [],         []]           //Canceled
    ];
#

To filter toolbar button validations.

wide shoal
sterile quail
#

Your senior developer looks quite junior to me

wide shoal
#
    //Find the proper status id
    let taskMenu = (items.find(f => f[0].includes(this.task.value.status.id))??[]);
    let menuFilter: number[];
    if (taskMenu.length === 0) {
      // Default to first element if status is not found
      this._logger.error("No matching status array element found, so default to Waiting on Data");
      menuFilter = items[0][this.task.value.taskType] as number[];
    }
    else {
      menuFilter = taskMenu[this.task.value.taskType] as number[];
    }
#

He admits he is still learning Angular and we are learning together.

#

He knows how to get things working but admits we might be doing somethings wrong.

obtuse dock
#

multi-dimensional arrays and number identifiers...
Is it a linear algebra course?

sterile quail
#

That's fine, but avoiding magic numbers is a general rule of development, unrelated to Angular

wide shoal
#

This was for tracking a filing and validating it through the steps.

sterile quail
#

Everything really. The statuses, the positions of the inner arrays, the fact that 0 means waiting on data. This is unmaintainable

wide shoal
#

Would you instead great objects for statuses?

sterile quail
#

I don't know your usecase well enough to suggest a solution, but I wouldn't use that, that's for sure.

wide shoal
#

I've been reading the docs like crazy. What else is the best resource for getting best practices down? What learning step should I take next?

wide shoal
#

So the buttons up top, disable or enable based on status and validation

#

You upload a file to validate, and the system checks if it needs anything else based on file uploading/deleting.

#

This all works, but it was such a pain to get the buttons, dropdowns and components to update the data when switching to a different record.

#

But the MD is tied to those statuses.

#

Based on if it's automated or manually processed.

tribal escarp
wide shoal
#

Like are we talking about our statuses being magic numbers and needing enums instead?

#

Oh I see after some more Googling. We shouldnt use the numbers directly. Need to be a variable?

tribal escarp
#

I suggest that you review the various eslint rules and pick ones that appeal to you and your codebase. Automated code review and analysis can be helpful with keeping a minimum standard to your code.
Personally, I turn on all the rules and then just configure and disable the ones that I need to. But that does make linting slow and very strict.