HH\Lib\Vec\fill

Meta Engineer?

This is available as Vec\fill in the www repository.

Returns a new vec of size $size where all the values are $value

namespace HH\Lib\Vec;

function fill<Tv>(
  int $size,
  Tv $value,
): vec<Tv>;

If you need a range of items not repeats, use Vec\range(0, $n - 1).

Time complexity: O(n) Space complexity: O(n)

Parameters

  • int $size
  • Tv $value

Returns

  • vec<Tv>

Examples

$result = Vec\fill(2, 100);
print_r($result);
//result: [100, 100]

$result = Vec\fill(0, 10);
print_r($result);
//result: []

$result = Vec\fill(5, 1);
print_r($result);
//result: [1,1,1,1,1]