Based on all this, I did this repo: GitHub - romeoman/hubspot-company-dedup: This is a script used for HubSpot as a custom code in a workflow that deduplicates a company, merges companies together even if they are multiple companies. · GitHub
Enhanced it a bit with some tracking.
hope it helps.