```coffeescript
App.Answers =

  nestedAnswers: ->
    $('.nested-answers').on 'cocoon:after-insert', (e, insertedItem) ->
      nestedAnswersCount = $("input[type='hidden'][name$='[given_order]']").size()
      $(insertedItem).find("input[type='hidden'][name$='[given_order]']").val(nestedAnswersCount)

  initialize: ->
    App.Answers.nestedAnswers()
```

Initialize answers 'after-insert' callback to keep answers order
user
```coffeescript
App.Answers =

  initializeAnswers: (answers) ->
    $(answers).on 'cocoon:after-insert', (e, new_answer) ->
      given_order = App.Answers.maxGivenOrder(answers) + 1
      $(new_answer).find("[name$='[given_order]']").val(given_order)

  maxGivenOrder: (answers) ->
    max_order = 0
    $(answers).find("[name$='[given_order]']").each (index, answer) ->
      value = parseFloat($(answer).val())
      max_order = if value > max_given_order then value else max_given_order
    return max_given_order

  nestedAnswers: ->
    $('.js-answers').each (index, answers) ->
      App.Answers.initializeAnswers(answers)

  initialize: ->
    App.Answers.nestedAnswers()
```
assistant