Avoid code duplication by using ?: and array indexing instead of if..else