<commit_before>/**
 * Copyright 2003-present <NAME>. All rights reserved.
 * Licensed under the terms of the MIT license.
 *
 * @flow
 */

export default function addDigits(
  aDigits: Array<number>,
  bDigits: Array<number>,
  base: number
): Array<number> {
  let result = [];
  let carry = 0;
  const aLength = aDigits.length;
  const bLength = bDigits.length;
  for (let i = 0; i < aLength || i < bLength || carry; i++) {
    const aDigit = i < aLength ? aDigits[aLength - i - 1] : 0;
    const bDigit = i < bLength ? bDigits[bLength - i - 1] : 0;
    const sum = aDigit + bDigit + carry;
    result.push(sum % base);

    // ~~ here is the equivalent of Math.floor; used to avoid V8 de-opt,
    // "Reference to a variable which requires dynamic lookup".
    carry = ~~(sum / base);
  }
  return result.length ? result.reverse() : [0];
}
<commit_msg>Revert "Replace `unshift()` with `push()` plus `reverse()`"<commit_after>/**
 * Copyright 2003-present <NAME>. All rights reserved.
 * Licensed under the terms of the MIT license.
 *
 * @flow
 */

export default function addDigits(
  aDigits: Array<number>,
  bDigits: Array<number>,
  base: number
): Array<number> {
  let result = [];
  let carry = 0;
  const aLength = aDigits.length;
  const bLength = bDigits.length;
  for (let i = 0; i < aLength || i < bLength || carry; i++) {
    const aDigit = i < aLength ? aDigits[aLength - i - 1] : 0;
    const bDigit = i < bLength ? bDigits[bLength - i - 1] : 0;
    const sum = aDigit + bDigit + carry;
    result.unshift(sum % base);

    // ~~ here is the equivalent of Math.floor; used to avoid V8 de-opt,
    // "Reference to a variable which requires dynamic lookup".
    carry = ~~(sum / base);
  }
  return result.length ? result : [0];
}

{'fraction_non_alphanumeric': 0.14122355631789593, 'fraction_numerical': 0.0137221269296741, 'mean_word_length': 2.9592760180995477, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 11, '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': '6092303', 'n_tokens_mistral': 613, 'n_tokens_neox': 593, 'n_words': 200}