You could use a regex instead: 

```javascript
subscription.managementEndpointUrl.replace(/\/\/*^/, "/")
```

Replaces multiple "/" characters at the end of a string with a single one. Would probably be faster as well, and gets rid of an extra function.