Is there a way to make this code more concise?
const result = getResult();
if (!result) {
return;
}
// Work with result
I have several instances of this code in my project and I'm looking for a simpler solution like:
const result = getResult() || return;
// Work with result
EDIT: I only want to persist inputs that can be converted.
const parseInput = (input: string): void => {
const convertedInput = convert(input);
if (!convertedInput) {
return;
}
persist(convertedInput);
}
I am aware that I could call the converter twice, but I want to avoid that:
const parseInput = (input: string): void => {
if (!convert(input)) {
return;
}
persist(convert(input));
}