Last active
May 28, 2024 13:14
-
-
Save z-hao-wang/c694ad37d61cf48eecb92b2ba5156e44 to your computer and use it in GitHub Desktop.
Att bill payment split calculate
This file contains 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
var values=document.getElementsByClassName('pad-r-xxxxs-sm'); | |
var nums = []; | |
for (let i = 0; i < values.length; i++) { | |
nums.push(parseFloat(values[i].innerText.substring(1))) | |
} | |
var total = 8 | |
let sharedIndex = 1; // todo : adjust this if there is late fee | |
let shared = nums[sharedIndex]; | |
let numbersEls = Array.from(document.getElementsByClassName('pad-r-xxxxs-sm')).slice(sharedIndex + 1); | |
let payments = []; | |
let startI = sharedIndex + 1 | |
for (let i = startI; i < nums.length; i++){ | |
if (numbersEls[i - startI].innerText.substring(1) < 16) { | |
payments.push(nums[i]); | |
} else { | |
payments.push(shared / total + nums[i]); | |
} | |
} | |
payments | |
let result = []; | |
for (let i = 0; i < numbersEls.length; i++) { | |
result.push(`${numbersEls[i].parentElement.parentElement.parentElement.innerText}: ${payments[i].toFixed(2)}`); | |
} | |
console.log(result) | |
var totalCost = payments.reduce((a, b) => b + a, 0) | |
result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment