No code here, just a gif showing MapShaper.
Step 1: Upload a GeoJSON to MapShaper. Try this one.
Step 2: Experiment with the different simplification algorithms, use the slider to choose how simplified you want your shapes, and watch for the number of line intersections that occur.
Step 3: Export your file as a topojson.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<img src="https://raw.githubusercontent.com/stamen/dwsd/master/img/mapshaper%20uk.gif">
</body>