<commit_before>$(document).ready(function() {
  const common = window.common;
  const { Observable } = window.Rx;
  const {
    addLoopProtect,
    challengeName,
    challengeType,
    challengeTypes
  } = common;

  common.init.forEach(function(init) {
    init($);
  });

  // only run if editor present
  if (common.editor.getValue) {
    const code$ = common.editorKeyUp$
      .debounce(750)
      .map(() => common.editor.getValue())
      .distinctUntilChanged()
      .shareReplay();

    // update storage
    code$.subscribe(
        code => {
          common.codeStorage.updateStorage(common.challengeName, code);
          common.codeUri.querify(code);
        },
        err => console.error(err)
      );

    code$
      // only run for HTML
      .filter(() => common.challengeType === challengeTypes.HTML)
      .flatMap(code => {
        return common.detectUnsafeCode$(code)
          .map(() => {
            const combinedCode = common.head + code + common.tail;

            return addLoopProtect(combinedCode);
          })
          .flatMap(code => common.updatePreview$(code))
          .flatMap(() => common.checkPreview$({ code }))
          .catch(err => Observable.just({ err }));
      })
      .subscribe(
        ({ err }) => {
          if (err) {
            console.error(err);
            return common.updatePreview$(`
              <h1>${err}</h1>
            `).subscribe(() => {});
          }
        },
        err => console.error(err)
      );

  }

  common.resetBtn$
    .doOnNext(() => {
      common.editor.setValue(common.replaceSafeTags(common.seed));
    })
    .flatMap(() => {
      return common.executeChallenge$()
        .catch(err => Observable.just({ err }));
    })
    .subscribe(
      ({ err, output, originalCode }) => {
        if (err) {
          console.error(err);
          return common.updateOutputDisplay('' + err);
        }
        common.codeStorage.updateStorage(challengeName, originalCode);
        common.updateOutputDisplay('' + output);
      },
      (err) => {
        if (err) {
          console.error(err);
        }
        common.updateOutputDisplay('' + err);
      }
    );

  Observable.merge(
    common.editorExecute$,
    common.submitBtn$
  )
    .flatMap(() => {
      common.appendToOutputDisplay('\n// testing challenge...');
      return common.executeChallenge$()
        .map(({ tests, ...rest }) => {<commit_msg>Fixes: Reset does not clear localstorage item<commit_after>$(document).ready(function() {
  const common = window.common;
  const { Observable } = window.Rx;
  const {
    addLoopProtect,
    challengeName,
    challengeType,
    challengeTypes
  } = common;

  common.init.forEach(function(init) {
    init($);
  });

  // only run if editor present
  if (common.editor.getValue) {
    const code$ = common.editorKeyUp$
      .debounce(750)
      .map(() => common.editor.getValue())
      .distinctUntilChanged()
      .shareReplay();

    // update storage
    code$.subscribe(
        code => {
          common.codeStorage.updateStorage(common.challengeName, code);
          common.codeUri.querify(code);
        },
        err => console.error(err)
      );

    code$
      // only run for HTML
      .filter(() => common.challengeType === challengeTypes.HTML)
      .flatMap(code => {
        return common.detectUnsafeCode$(code)
          .map(() => {
            const combinedCode = common.head + code + common.tail;

            return addLoopProtect(combinedCode);
          })
          .flatMap(code => common.updatePreview$(code))
          .flatMap(() => common.checkPreview$({ code }))
          .catch(err => Observable.just({ err }));
      })
      .subscribe(
        ({ err }) => {
          if (err) {
            console.error(err);
            return common.updatePreview$(`
              <h1>${err}</h1>
            `).subscribe(() => {});
          }
        },
        err => console.error(err)
      );

  }

  common.resetBtn$
    .doOnNext(() => {
      common.editor.setValue(common.replaceSafeTags(common.seed));
    })
    .flatMap(() => {
      return common.executeChallenge$()
        .catch(err => Observable.just({ err }));
    })
    .subscribe(
      ({ err, output, originalCode }) => {
        if (err) {
          console.error(err);
          return common.updateOutputDisplay('' + err);
        }
        common.codeStorage.updateStorage(challengeName, originalCode);
        common.codeUri.querify(originalCode);
        common.updateOutputDisplay('' + output);
      },
      (err) => {
        if (err) {
          console.error(err);
        }
        common.updateOutputDisplay('' + err);
      }
    );

  Observable.merge(
    common.editorExecute$,
    common.submitBtn$
  )
    .flatMap(() => {
      common.appendToOutputDisplay('\n// testing challenge...');
      return common.executeChallenge$()
        .map(({ tests, ...rest }) => {
{'fraction_non_alphanumeric': 0.1558811558811559, 'fraction_numerical': 0.002035002035002035, 'mean_word_length': 1.975181598062954, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5603152', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1410, 'n_words': 243}