// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Linq;
namespace Microsoft.ClearScript.Util
{
internal static class ArrayHelpers
{
public static void Iterate(this Array array, Action action)
{
if (array.Rank > 0)
{
var dimensions = Enumerable.Range(0, array.Rank);
if (dimensions.Aggregate(1, (count, dimension) => count * array.GetLength(dimension)) > 0)
{
Iterate(array, new int[array.Rank], 0, action);
}
}
}
private static void Iterate(Array array, int[] indices, int dimension, Action action)
{
if (dimension >= indices.Length)
{
action(indices);
}
else
{
var lowerBound = array.GetLowerBound(dimension);
var upperBound = array.GetUpperBound(dimension);
for (var index = lowerBound; index