102
103 const codeIsUnique = (code: string) => {
104 const isCodeUnique = products.find((p) => p.code === code);
105 if (isCodeUnique) {106 return false;107 }108 return true;
109 };
110 const options: Option<Partial<Category>>[] = [
The following pattern:
if (condition) {
return true
}
return false
can be refactored to:
return condition
When condition
is not a boolean value,
it can be cast into one using the Boolean
constructor.
function isEven(num: number) {
if (num % 2 === 0) return true
return false
}
async function userExists(name: string) {
if (await db.getUser(name)) return true
return false
}
function isEven(num: number) {
return num % 2 === 0
}
async function userExists(name: string) {
return Boolean(await db.getUser(name))
}