Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function check(transactions) {
- var balance = 0; // start with a zero balance
- var result = []; // start with an empty array
- for (var i = 0; i < transactions.length; i++) {
- var transaction = transactions[i]; // get the current transaction
- if (transaction[0] === 'Lend') { // if it's a lend
- balance += transaction[1]; // add the amount to the balance
- } else { // otherwise it's a borrow
- balance -= transaction[1]; // subtract the amount from the balance
- }
- if (balance === 0) { // if the balance is zero
- result.push(transaction); // add the transaction to the result
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement