This function can be the same as the function in sortKeys. I'm wondering if it makes sense to make it a `util.js` file that contains this and other currently repeated functions