Returned expression results in new array with at most n occurrences of value1 replaced with value2.
167485
public static Expression arrayReplace(String expression, Expression value1, Expression value2, long n) {
        return arrayReplace(x(expression), value1, value2, n);
    }
514766
function ( obj ) {
		var values = {},
		    count  = 0,
		    nth    = 0,
		    mode   = [],
		    result;

		// Counting values
		array.each( obj, function ( i ) {
			if ( !isNaN( values[i] ) ) {
				values[i]++;
			}
			else {
				values[i] = 1;
			}
		});

		// Finding the highest occurring count
		count = array.max( array.cast( values ) );

		// Finding values that match the count
		utility.iterate( values, function ( v, k ) {
			if ( v === count ) {
				mode.push( number.parse( k ) );
			}
		});

		// Determining the result
		nth = mode.length;

		if ( nth > 0 ) {
			result = nth === 1 ? mode[0] : mode;
		}

		return result;
	}
95034
function () {
    var pattern = /\{(\d+)\}/g;
    //safer way to convert a pseudo array to an object array
    var args = Array.prototype.slice.call(arguments);
    var s = args.shift();
    return s.replace(pattern, function(c, d) {
      var replacement = args[d] ;
      if (lib.isNull(replacement)) {
        replacement = "";
      }
      return replacement;
    });
  }
286695
private static int[] filter(int[] org, int skip1, int skip2) {
        int n = 0;
        int[] dest = new int[org.length - 2];
        for (int w : org) {
            if (w != skip1 && w != skip2) dest[n++] = w;
        }
        return dest;
    }
617621
def array_values(expr):
    """"""
    if isinstance(expr, Array):
        return expr.get_elems(all_subs(expr._bounds))
    elif isinstance(expr, list):
        vals = [array_values(x) for x in expr]
        return flatten(vals)
    else:
        return [expr]
588172
public static Object[] sub(Object array, int start, int end) {
		return sub(array, start, end, 1);
	}
383852
function arrayAllocExpression(t, array) {
	return t.newExpression(t.identifier('Array'), [
		t.memberExpression(array, t.identifier('length')),
	]);
}
262555
private function arrayValue($value) : Expr\Array_
    {
        $items = [];
        $lastKey = -1;
        foreach ($value as $itemKey => $itemValue) {
            // for consecutive, numeric keys don't generate keys
            if (null !== $lastKey && ++$lastKey === $itemKey) {
                $items[] = new Expr\ArrayItem(
                    $this->__invoke($itemValue)
                );
            } else {
                $lastKey = null;
                $items[] = new Expr\ArrayItem(
                    $this->__invoke($itemValue),
                    $this->__invoke($itemKey)
                );
            }
        }

        return new Expr\Array_($items);
    }
800295
function(array, n) {
      var ret = [];
      var sz = _.size(array);

      if (n <= 0) return [];
      if (n === 1) return array;

      for(var index = 0; index < sz; index += n) {
        ret.push(array[index]);
      }

      return ret;
    }
1133394
function arraySpliceOut(mutate, at, arr) {
    var newLen = arr.length - 1;
    var i = 0;
    var g = 0;
    var out = arr;
    if (mutate) {
        i = g = at;
    } else {
        out = new Array(newLen);
        while (i < at) {
            out[g++] = arr[i++];
        }
    }
    ++i;
    while (i <= newLen) {
        out[g++] = arr[i++];
    }if (mutate) {
        out.length = newLen;
    }
    return out;
}
1337650
def push(x, n = 1)
      x = [x] unless x.is_a? Array
      x.each { |value| _digest(value, n) }
    end
1154387
public static Expression arrayReplace(JsonArray array, Expression value1, Expression value2, long n) {
        return arrayReplace(x(array), value1, value2, n);
    }
1312110
private int[] nArgMin(int n, double[] values, int startIdx, int endIdx){
		int indices[] = new int[n];
		for (int i=0; i<n; i++){
			double minValue = Double.MAX_VALUE;
			for (int j=startIdx; j<endIdx+1; j++){
				if (values[j] < minValue){
					boolean alreadyUsed = false;
					for (int k=0; k<i; k++){
						if (indices[k]==j){
							alreadyUsed = true;
						}
					}
					if (!alreadyUsed){
						indices[i] = j;
						minValue = values[j];
					}
				}
			}
		}
		return indices;
	}
735572
public static Object toPrimitiveLongArray(List<?> values)
    {
        long[] array = new long[values.size()];
        int cursor = 0;
        
        for(Object o : values)
        {
            array[cursor] = (Long) o;
            cursor ++;
        }
        return array;
    }
647978
public void nextIteration(double[][] means) {
    this.means = means;
    changed = false;
    final int k = means.length;
    final int dim = means[0].length;
    centroids = new double[k][dim];
    sizes = new int[k];
    Arrays.fill(varsum, 0.);
  }
671667
public static String substituteValueInExpression(String expression, String newValue)
   {
      ExpressionTemplate t = new ExpressionTemplate(expression);
      if (newValue != null && (getExpressionKey(t.getTemplate()) == null ||
            (t.isComplex()  && !newValue.equals(t.getValue()))))
         return newValue;

      String result = t.getSubstitution();
      if (!t.isComplex() && newValue != null)
      {
         int start = result.lastIndexOf(":$");
         start = result.indexOf(":", start + 1);
         int end = result.indexOf("}", start + 1);

         if (start < 0 || end < 0 || start == result.lastIndexOf("${:}") + 2)
            return result;

         result = result.substring(0, start + 1) + newValue +  result.substring(end);
      }
      return result;
   }
4378
public static <E> E nth(long count, E[] array) {
        final Iterator<E> filtered = new FilteringIterator<E>(new ArrayIterator<E>(array), new Nth<E>(count));
        return new FirstElement<E>().apply(filtered);
    }