Skip to content

Instantly share code, notes, and snippets.

@z-hao-wang
Last active January 4, 2025 23:50
Show Gist options
  • Select an option

  • Save z-hao-wang/c694ad37d61cf48eecb92b2ba5156e44 to your computer and use it in GitHub Desktop.

Select an option

Save z-hao-wang/c694ad37d61cf48eecb92b2ba5156e44 to your computer and use it in GitHub Desktop.
Att bill payment split calculate
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)))
}
const total = 8
let sharedIndex = 1; // todo : adjust this if there is late fee
let shared = nums[sharedIndex];
console.error(`shared: ${shared}`)
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 (i == nums.length - 1) { // last one is iwatch
payments.push(nums[i]);
} else {
payments.push(shared / total + nums[i] + 0.01);
}
}
payments
let result = [];
for (let i = 0; i < numbersEls.length; i++) {
result.push(`${numbersEls[i].parentElement.parentElement.parentElement.innerText.replace(/discount/, '')} total: ${payments[i].toFixed(2)}`);
}
console.error(result)
var totalCost = payments.reduce((a, b) => b + a, 0)
console.error("totalCost", totalCost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment