MCPcopy Index your code
hub / github.com/nodejs/node / sample

Function sample

deps/v8/tools/clusterfuzz/js_fuzzer/random.js:100–115  ·  view source on GitHub ↗

* As above for an arbitrary number of elements with a fast implementation * for 1 or 2 elements.

(array, count)

Source from the content-addressed store, hash-verified

98 * for 1 or 2 elements.
99 */
100function sample(array, count) {
101 assert(count > 0);
102 assert(array.length >= count);
103
104 // Fast paths for 1 or 2 elements.
105 if (count == 1) {
106 return [single(array)];
107 }
108 if (count == 2) {
109 return sampleOfTwo(array);
110 }
111
112 const copy = Array.from(array);
113 shuffle(copy);
114 return copy.slice(0, count);
115}
116
117function shuffle(array) {
118 for (let i = 0; i < array.length - 1; i++) {

Callers 1

test_random.jsFile · 0.85

Calls 6

sampleOfTwoFunction · 0.85
shuffleFunction · 0.85
singleFunction · 0.70
sliceMethod · 0.65
assertFunction · 0.50
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…