str && str.length === 0 is someway redundant. We don't need an additional check as the string will always come from a substring