Closed matteocng closed 7 years ago
Thanks for that. I added comments 😄
Can I wait for something more or time to merge? 😄
Sorting a second time using sort-keys-recursive
and passing compareFunction
works but it doesn't seem ideal, because the function would be applied to all keys recursively, not just the keys at the first level.
What do you think about this instead:
# After sorting, we move some fields in new positions for esthetic effect.
compareFunction = (a, b) -> KEYWORDS.sort.indexOf(a) - KEYWORDS.sort.indexOf(b)
output = Object.keys(input).sort(compareFunction).reduce (acc, key) ->
acc[key] = input[key]
acc
, {} # Object, second argument of reduce(), initial value of 'acc'.
@matteocng I like this new approach, can you commit it? want to know if tests are green with this change
I have updated the commit, also adding a small clarification about the behaviour of the default sort function (and link to MDN) in the README
and code comments.
Commits:
Fixes #35.