Sets the array item at a certain index, including multiple dimensions

@param {Array} arr The array to search
@param {Array<ExpressionStatement>} dimensions An array of indexes
@param {String|Number} val The value to put in the array
@param {ExecutionContext} data The execution data context
@private
function setArrayIndexAt(arr, dimensions, val, data) {
    var currentDimension = dimensions[0].execute(data);
    data.validate(currentDimension, 'number');
    currentDimension -= 1;
    if (currentDimension < 0) currentDimension = 0;

    if (arr.length <= currentDimension) throw new Error('Invalid array bounds');
    var item = arr[currentDimension];
    if (dimensions.length > 1) {
        if (!Array.isArray(item)) throw new Error('Invalid array dimensions');
        return setArrayIndexAt(arr[currentDimension], dimensions.slice(1), val,  data);
    } else arr[currentDimension] = val;
}