code: function updateTone(user, tones, maintainHistory) {
    var maxScore = 0.0;
    var primaryTone = null;
    var primaryToneScore = null;
  
    tones.forEach(function(tone) {
      if (tone.score > maxScore) {
        maxScore = tone.score;
        primaryTone = tone.tone_name.toLowerCase();
        primaryToneScore = tone.score;
      }
    });
  
    // update user tone
    user.tone.current = primaryTone;
  
    if (maintainHistory) {
      if (typeof user.tone.history === 'undefined') {
        user.tone.history = [];
      }
      user.tone.history.push({
        tone_name: primaryTone,
        score: primaryToneScore,
      });
    }
  }
docs: updateTone updates the user tone with the primary tone - the tone with the largest score
  @param user a json object representing user information (tone) to be used in conversing with the assistant Service
  @param tones an array containing the document-level tones in the payload returned by the Tone Analyzer