<commit_before>const tokens = [
  { regex: /^[-+]?\d+/,      action: (x) => Number(x) },
  { regex: /^plus/,          action: (x) => (y) => x + y },
  { regex: /^minus/,         action: (x) => (y) => x - y },
  { regex: /^multipliedby/,  action: (x) => (y) => x * y },
  { regex: /^dividedby/,     action: (x) => (y) => x / y },
  { regex: /^.+/,            action: () => { throw new Error('Argument Error') } }
]

const applyTokens = (str, acc) => {
  if(!str) return acc

  const { regex, action } = tokens.find((t) => str.match(t.regex))
  const matchedValue = str.match(regex)[0]
  const strRemaining = str.replace(regex, '')

  acc = typeof acc === 'function'
    ? acc(action(matchedValue))
    : action(acc)

  return applyTokens(strRemaining, acc)
}

const parseQuestion = (question) => {
  const trimmed = question.replace(/ |\?|What is/g, '') // remove crud
  return applyTokens(trimmed, x => x)
}

class WordProblem {
  constructor(question) {
    this.answer = parseQuestion.bind(null, question)
  }
}

const ArgumentError = () =>
  new Error('Argument Error')

export default {
  WordProblem,
  ArgumentError
}<commit_msg>Final edits to wordy<commit_after>const ArgumentError = () => new Error('Argument Error')

const tokens = [
  { regex: /^[-+]?\d+/,      action: (x) => Number(x) },
  { regex: /^plus/,          action: (x) => (y) => x + y },
  { regex: /^minus/,         action: (x) => (y) => x - y },
  { regex: /^multipliedby/,  action: (x) => (y) => x * y },
  { regex: /^dividedby/,     action: (x) => (y) => x / y },
  { regex: /^.+/,            action: () => { throw ArgumentError() } }
]

const applyTokens = (str, acc) => {
  if(!str) return acc

  const { regex, action } = tokens.find((t) => str.match(t.regex))
  const matchedValue = str.match(regex)[0]
  const strRemaining = str.replace(regex, '')

  acc = typeof acc === 'function'
    ? acc(action(matchedValue))
    : action(acc)

  return applyTokens(strRemaining, acc)
}

class WordProblem {
  constructor(question) {
    this.answer = () => {
      const trimmed = question.replace(/ |\?|What|is/g, '') // remove crud
      return applyTokens(trimmed, x => x)
    }
  }
}

export default {
  WordProblem,
  ArgumentError
}
{'fraction_non_alphanumeric': 0.20280669986419195, 'fraction_numerical': 0.0009053870529651426, 'mean_word_length': 2.810344827586207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '3848766', 'n_tokens_mistral': 784, 'n_tokens_neox': 776, 'n_words': 189}