The anchormap variable is an array that we will use to associate the anchor with the page slug to redirect to.
window.location.href.split("#") will take the current URL and split it at the # and then use the first portion of the split, which is why we have 0 inside the square brackets. The first portion will be everything in front of the # in the URL.
window.location.href.indexOf("recycling-waste-management") will check to see which main service page we are currently on. In this case is check to see if the main service is the recycling-waste-management page. If it finds recycling-waste-management as part of the URL it will return a number greater than -1. If nothing is found, indexOf will return -1.
window.location.hash.substring(1) will find the # and give us the anchor in the URL.
window.location.replace( currentLocation + anchorMap[hash] ) will replace the current URL with whatever is passed into the function. In this case we are redirecting to the current url minus the anchor (currentLocation) followed by the slug that is associated to the found anchor.
Put this code inside the script tags where you like on the page and it will run automatically when the page is requested.
Hope this help!