function end_trial() {

      // kill any remaining setTimeout handlers
      jsPsych.pluginAPI.clearAllTimeouts();

      // measure response time
      var end_time = performance.now();
      var rt = end_time - start_time;

      // copy responses
      const copy = trial.backwards ? [...responses].reverse() : [...responses];

      // score responses
      var score_ls = longest_subsequence(copy, trial.sequence);
      var score_pc = partial_credit(copy, trial.sequence);
      var score_an = (score_pc == trial.sequence.length) ? 1 : 0;

      // gather the data to store for the trial
      var trial_data = {
        sequence: trial.sequence,
        sequence_length: trial.sequence.length,
        backwards: trial.backwards,
        responses: responses,
        score_an: score_an,
        score_pc: score_pc,
        score_ls: score_ls,
        rt: rt
      };

      // clear the display
      display_element.innerHTML = '';

      // move on to the next trial
      jsPsych.finishTrial(trial_data);
    }
// function to end trial when it is time

function to end trial when it is time
function to end trial when it is time
function end_trial() {
      jsPsych.pluginAPI.clearAllTimeouts();
      var end_time = performance.now();
      var rt = end_time - start_time;
      const copy = trial.backwards ? [...responses].reverse() : [...responses];
      var score_ls = longest_subsequence(copy, trial.sequence);
      var score_pc = partial_credit(copy, trial.sequence);
      var score_an = (score_pc == trial.sequence.length) ? 1 : 0;
      var trial_data = {
        sequence: trial.sequence,
        sequence_length: trial.sequence.length,
        backwards: trial.backwards,
        responses: responses,
        score_an: score_an,
        score_pc: score_pc,
        score_ls: score_ls,
        rt: rt
      };
      display_element.innerHTML = '';
      jsPsych.finishTrial(trial_data);
    }
function end_trial ( ) { jsPsych . pluginAPI . clearAllTimeouts ( ) ; var end_time = performance . now ( ) ; var rt = end_time - start_time ; const copy = trial . backwards ? [ ... responses ] . reverse ( ) : [ ... responses ] ; var score_ls = longest_subsequence ( copy , trial . sequence ) ; var score_pc = partial_credit ( copy , trial . sequence ) ; var score_an = ( score_pc == trial . sequence . length ) ? 1 : 0 ; var trial_data = { sequence : trial . sequence , sequence_length : trial . sequence . length , backwards : trial . backwards , responses : responses , score_an : score_an , score_pc : score_pc , score_ls : score_ls , rt : rt } ; display_element . innerHTML = '' ; jsPsych . finishTrial ( trial_data ) ; }
function to end trial when it is time
function to end trial when it is time
// kill any remaining setTimeout handlers
 // measure response time
 // copy responses
 // score responses
 // gather the data to store for the trial
 // clear the display
 // move on to the next trial
