Reiterating Function Logic in Code: Early Returns Explained
I've suggested this before but wanted to reiterate: sheets would be much simpler if you could "return early" This is a common best practice in coding. It makes functions much simpler / easier to manage. Example function (mimicks a row in Clay)
const company = testCompany
const employeeCount = getEmployeeCount()
const funding = getFunding()
if (funding < 10 && employeeCount > 20) {
const aiDescription = getAiDescription() // must add run condition based on funding employee count
const rating = getRating() // must add run condition based on funding employee count
if (rating > 5) {
const contacts = findContacts(company) // must add run condition based on funding employee count and rating
const emails = find emails() // must add run condition based on funding employee count and rating
}
}
But if you "return early" the function is a lot simpler
const company = testCompany
const employeeCount = getEmployeeCount() // returns FTE count
const funding = getFunding()
if (funding > 10 || employeeCount < 20) {
return // ends "row functions"
}
const aiDescription = getAiDescription() // no run conditions needed
const rating = getRating() // no run conditions needed
if (rating < 5) {
return
}
const contacts = findContacts(company)
const emails = find emails()
const contacts = findContacts(company)
const emails = find emails()
If you could do this in a sheet (i.e. "end" the row based on a condition) it would save you a TON of complexity in have to add run conditions to every subsequent column