I read Robert Martin's Clean Code: Function chapter. In this chapter, the best number of arguments of function is single argument. So, it is good to abstract that argument and function should be separated if it have various roles.
In practice, I wrote function that accepts single/plural arguments using Typescript like below.
Context
Our web server have various permissions to enable a specific functionality, thus client should separate each features per permission. To implement this, I wrote function which receives single/plural permission as argument and check that permission is permitted. At first, I wrote this code like below
const isPermitted = (permissions: Permission | Permission[]): boolean => {};
But, I have problem for naming argument name permissions
because it could be single and plural. I considered between permission
and permissions
. Consequently, I concluded to change like below.
const isPermitted = (permissions: Permission[]): boolean => {};
Argument is single, but it always accepts array only. I thought it was good refactoring. In this context, is it proper solution?