Sha256: 07f009fb0b37677f0d8576f670607af73fa1360aa76840d98acc18b1668d7169
Contents?: true
Size: 644 Bytes
Versions: 169
Compression:
Stored size: 644 Bytes
Contents
# frozen_string_literal: true # Splits an array into two groups, where the 1st group is a randomly selected # sample of the input (of the specified size) and the 2nd group is the remainder. # # This function takes 2 parameters: # * The array to split (Array) # * The number of items to sample from the array (Integer) # # Returns an array of [<sample>, <remainder>]. Puppet::Functions.create_function(:'canary::random_split') do dispatch :rand do param 'Array', :arr param 'Integer', :size end def rand(arr, size) canaries = arr.sample(size) rest = arr.reject { |r| canaries.include?(r) } [canaries, rest] end end
Version data entries
169 entries across 169 versions & 1 rubygems