Skip to content

Instantly share code, notes, and snippets.

@pjurczynski
Created July 25, 2014 09:12
Show Gist options
  • Save pjurczynski/9d2809c87d2693ebc90f to your computer and use it in GitHub Desktop.
Save pjurczynski/9d2809c87d2693ebc90f to your computer and use it in GitHub Desktop.
def count_customers(customer_id, order_count, totals, repeat_customers, new_customers, newly_promising_customers, newly_loyal_customers)
total_orders = totals.fetch(customer_id, 0)
if total_orders == 1 || order_count == total_orders
new_customers += 1
elsif total_orders == 2
newly_promising_customers += 1
elsif (total_orders - order_count) < 4
newly_loyal_customers += 1
elsif order_count != total_orders
repeat_customers += 1
end
[repeat_customers, new_customers, newly_promising_customers, newly_loyal_customers]
end
def count_customers(customer_id, order_count, totals, repeat_customers, new_customers, newly_promising_customers, newly_loyal_customers)
total_orders = totals.fetch(customer_id, 0)
if total_orders == 1
new_customers += 1
else
if total_orders > 3
newly_loyal_customers += 1 if (total_orders - order_count) < 4
else
newly_promising_customers += 1
end
order_count == total_orders ? new_customers += 1 : repeat_customers += 1
end
[repeat_customers, new_customers, newly_promising_customers, newly_loyal_customers]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment