Created
June 6, 2025 14:00
-
-
Save yshapiraGC/2523469b2c34b50faf4a0b0e83725144 to your computer and use it in GitHub Desktop.
You're developing a system to analyze transactions for potential fraud. You have a list of transactions, each with a variety of attributes like amount, currency, status, and a fraud score. Your goal is to calculate total amounts for different currencies only for transactions flagged non clean. You shall refactor ONLY the analyze_transactions met…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transactions = [ | |
{ id: 1, amount: 100, currency: 'USD', status: 'potential_fraud', fraud_score: 85 }, | |
{ id: 2, amount: 200, currency: 'EUR', status: 'potential_fraud', fraud_score: 90 }, | |
{ id: 3, amount: 150, currency: 'USD', status: 'clean', fraud_score: 10 }, | |
{ id: 4, amount: 300, currency: 'USD', status: 'potential_fraud', fraud_score: 88 }, | |
{ id: 5, amount: 250, currency: 'EUR', status: 'clean', fraud_score: 5 }, | |
{ id: 6, amount: 400, currency: 'GBP', status: 'potential_fraud', fraud_score: 92 }, | |
{ id: 7, amount: 50, currency: 'GBP', status: 'potential_fraud', fraud_score: 80 } | |
] | |
class Task | |
def initialize(transactions) | |
@transactions = transactions | |
end | |
def analyze_transactions | |
def total_usd_fraud | |
total_usd = 0 | |
@transactions.each do |tx| | |
if tx[:currency] == 'USD' && tx[:status] == 'potential_fraud' | |
total_usd += tx[:amount] | |
end | |
end | |
total_usd | |
end | |
def total_eur_fraud | |
total_eur = 0 | |
@transactions.each do |tx| | |
if tx[:currency] == 'EUR' && tx[:status] == 'potential_fraud' | |
total_eur += tx[:amount] | |
end | |
end | |
total_eur | |
end | |
def total_gbp_fraud | |
total_gbp = 0 | |
@transactions.each do |tx| | |
if tx[:currency] == 'GBP' && tx[:status] == 'potential_fraud' | |
total_gbp += tx[:amount] | |
end | |
end | |
total_gbp | |
end | |
end | |
def run | |
analyze_transactions | |
puts total_usd_fraud, total_eur_fraud, total_gbp_fraud | |
end | |
end | |
class Solution | |
def initialize(transactions) | |
@transactions = transactions | |
end | |
def analyze_transactions | |
# TODO impl: write your code here | |
end | |
def run | |
analyze_transactions | |
puts total_usd_fraud, total_eur_fraud, total_gbp_fraud | |
end | |
end | |
Task.new(transactions).run | |
Solution.new(transactions).run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment