/* Add a number to an array number at a specified index.
*
171538
function addNum(arr, num, index = 0) {
  if (arr[index] == undefined) arr[index] = 0;
  arr[index] += num;
}
623803
public void add(int num, int[] indices) {
        for (int i = 0; i < indices.length; ++i)
            indices[i] += num;
    }
1348952
function addArr(arr1, arr2, shift = 0) {
  arr2.forEach((singlet, i) => {
    addNum(arr1, singlet, i + shift);
  });
}
397086
public void set(int index, float value)
    {
        if (index < offset + array.length && index >= offset)
        {
            array[index - offset] += value;
        }
        else if (index < offset)
        {  //expand from left
            int gap = offset - index;
            int newSize = gap + array.length;
            float[] newArray = new float[newSize];
            newArray[0] = value;
            for (int i = 0; i < array.length; i++)
            {
                newArray[gap + i] = array[i];
            }
            this.offset = index;
            this.array = newArray;
        }
        else
        {
            int gap = index - (array.length + offset - 1);
            int newSize = array.length + gap;
            float[] newArray = new float[newSize];
            newArray[newSize - 1] = value;
            for (int i = 0; i < array.length; i++)
            {
                newArray[i] = array[i];
            }
            this.array = newArray;
        }
    }
9852
public static void insertSort(int[] arrays) {
        for (int i = 1; i < arrays.length; i++) {
            int currentNumber = arrays[i];
            int j = i - 1;
            while (j >= 0 && arrays[j] > currentNumber) {
                arrays[j + 1] = arrays[j--];
            }
            arrays[j + 1] = currentNumber;
        }
    }
368082
@Override
  public boolean addAll(int index, Collection<? extends Float> c) {
    if (index < 0 || index > size) {
      throw new IndexOutOfBoundsException();
    }
    ensureCapacity(size + c.size());
    size += c.size();
    for (int i = size + c.size() - 1, j = size - 1; j >= index; i--, j--) {
      elements[i] = elements[j];
    }
    for (float e : c) {
      elements[index++] = e;
    }
    return c.size() > 0;
  }
539177
public boolean addAll(int index, Collection<? extends XEvent> c) {
		for (XEvent event : c) {
			try {
				events.insert(event, index);
			} catch (IOException e) {
				e.printStackTrace();
			}
			index++;
		}
		return (c.size() > 0);
	}
226615
public StrBuilder insert(int index, char c) {
		moveDataAfterIndex(index, 1);
		value[index] = c;
		this.position = Math.max(this.position, index) + 1;
		return this;
	}
1065707
@Override
    public void add(int idx, double val) {
        int i = Arrays.binarySearch(indices, 0, used, idx);
        if (i >= 0) {
            // Just add to the existing value.
            values[i] += val;
            return;
        } 
        int insertionPoint = -(i + 1);
        indices = insert(indices, insertionPoint, idx);
        values = insert(values, insertionPoint, val);
        used++;
    }
1164166
public ScriptBuilder number(int index, long num) {
        if (num == -1) {
            return op(index, OP_1NEGATE);
        } else if (num >= 0 && num <= 16) {
            return smallNum(index, (int) num);
        } else {
            return bigNum(index, num);
        }
    }
312687
public int set(int index, int element)
    {
        boundsCheck(index);
        int prev = array[index];
        array[index] = element;
        return prev;
    }
710286
function (child, index) {
            var indexOffset = this._calculateIndexOffsetForChild(child);
            this.$parent.addChild(child, {childIndex: index + indexOffset});
        }
542458
public void setValue (int index, String value)
    {
    if (index >= 0 && index < length) {
        data[index*5+4] = value;
    } else {
        badIndex(index);
    }
    }
910066
function(offset) {
        var index = this._indexArray,
            l = this.index_pointer;
        index[0 + l] = 0 + offset;
        index[1 + l] = 1 + offset;
        index[2 + l] = 2 + offset;
        index[3 + l] = 1 + offset;
        index[4 + l] = 2 + offset;
        index[5 + l] = 3 + offset;
        this.index_pointer += 6;
    }
697670
private void inc(ArrayList<Integer> array, int index) {
        array.set(index, array.get(index) + 1);
    }
5627
protected final Object arrayLookup(Object array, int index) {
        LOGGER.trace("get value from array index " + index);
        return Array.get(array, index);
    }
839366
function subIndex(arr, index) {
  if (!Array.isArray(arr)) {
    var arrType = typeof arr;
    var stringifiedArr = String(arr);

    throw new TypeError(
      'Expected an array, but got ' +
      (stringifiedArr === arrType ? stringifiedArr : stringifiedArr + ' (' + arrType + ')') +
      '.'
    );
  }

  if (arr.length === 0) {
    throw new Error('Expected a non-empty array, but got [].');
  }

  var indexType = typeof index;
  var stringifiedIndex = String(index);

  if (indexType !== 'number') {
    throw new TypeError(
      'Expected an index of array (integer), but got ' +
      (stringifiedIndex === indexType ? stringifiedIndex : stringifiedIndex + ' (' + indexType + ')') +
      '.'
    );
  }

  if (!isFinite(index) || Math.floor(index) !== index) {
    throw new Error('Expected an index of array (integer), but got ' + String(index) + '.');
  }

  if (index < 0) {
    throw new Error('Expected an index of array (positive integer), but got ' + String(index) + '.');
  }

  var arrLength = arr.length;

  if (index >= arrLength) {
    throw new Error(
      'Expected an index of array, but got ' +
      String(index) +
      ' that exceeds the last index of the array (' + (arrLength - 1) + ').');
  }

  if (arr.length === 1) {
    return null;
  }

  if (index === 0) {
    return 1;
  }

  return index - 1;
}