What aspect of the KISS (Keep It Simple, Stupid) principle is violated in this function implementation?
function calculateDiscount(amount, userType, membershipDuration, previousPurchases, seasonalDiscount) {
let discount = 0;
if (userType === 'premium' && membershipDuration > 12) {
if (previousPurchases > 1000) {
discount = amount * 0.2;
if (seasonalDiscount) {
discount += amount * 0.1;
if (previousPurchases > 5000) {
discount += amount * 0.05;
} else if (membershipDuration > 24) {
discount += amount * 0.03;
}
}
} else if (membershipDuration > 24) {
discount = amount * 0.15;
if (seasonalDiscount) {
discount += amount * 0.05;
}
}
}
return discount;
This code violates KISS by implementing overly complex nested conditional logic that's hard to understand and maintain. Following KISS, the code should be simplified, possibly by breaking down the discount calculation into smaller, more manageable functions or using a more straightforward calculation strategy. A better approach would be to separate different discount types and combine them using a more linear approach, making the code easier to understand and maintain.