<commit_before>const insert = (prev, value, next) => {
  prev.next = next.prev = { prev, value, next }
}

const remove = ({prev, value, next}) => {
  [prev.next, next.prev] = [next, prev]
  return value
}

function * elements (list) {
  for (let el = list; (el = el.next) !== list; yield el);
}

function reduce (list, fn, acc) {
  for (var el of elements(list)) {
    acc = fn(acc, el)
  }
  return acc
}

function find (list, value) {
  for (var el of elements(list)) {
    if (el.value === value) {
      return el
    }
  }
}

const linkedList2 = () => {
  const list = {}
  list.prev = list.next = list

  return Object.freeze({
    push:     (value) => insert(list.prev, value, list),
    unshift:  (value) => insert(list, value, list.next),
    pop:      () => remove(list.prev),
    shift:    () => remove(list.next),
    count:    () => reduce(list, count => ++count, 0),
    delete:   (value) => {
                let element = find(list, value)
                if(element) {
                  remove(element)
                }
              }
  })
}

export default linkedList2
<commit_msg>Updating linked list<commit_after>// Copy of http://exercism.io/submissions/a06f1b8bd6a64d1fb5501b7d848de4c1 as I try to understand it

const insert = (prev, value, next) => {
  prev.next = next.prev = { prev, value, next }
}

const remove = ({prev, value, next}) => {
  [prev.next, next.prev] = [next, prev]
  return value
}

function * elements (list) {
  for (let el = list; (el = el.next) !== list; yield el);
}

function reduce (list, fn, acc) {
  for (var el of elements(list)) {
    acc = fn(acc, el)
  }
  return acc
}

function find (list, value) {
  for (var el of elements(list)) {
    if (el.value === value) {
      return el
    }
  }
}

const linkedList2 = () => {
  const list = {}
  list.prev = list.next = list

  return Object.freeze({
    push:     (value) => insert(list.prev, value, list),
    unshift:  (value) => insert(list, value, list.next),
    pop:      () => remove(list.prev),
    shift:    () => remove(list.next),
    count:    () => reduce(list, count => ++count, 0),
    delete:   (value) => {
                let element = find(list, value)
                if(element) {
                  remove(element)
                }
              }
  })
}

export default linkedList2

{'fraction_non_alphanumeric': 0.16183470359151883, 'fraction_numerical': 0.01038511466897447, 'mean_word_length': 2.2701555869872703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4432569', 'n_tokens_mistral': 804, 'n_tokens_neox': 785, 'n_words': 214}