MCPcopy
hub / github.com/tinymce/tinymce / map

Function map

modules/katamari/src/main/ts/ephox/katamari/api/Arr.ts:62–72  ·  view source on GitHub ↗
(xs: ArrayLike<T>, f: ArrayMorphism<T, U>)

Source from the content-addressed store, hash-verified

60};
61
62export const map = <T = any, U = any>(xs: ArrayLike<T>, f: ArrayMorphism<T, U>): U[] => {
63 // pre-allocating array size when it's guaranteed to be known
64 // http://jsperf.com/push-allocated-vs-dynamic/22
65 const len = xs.length;
66 const r = new Array(len);
67 for (let i = 0; i < len; i++) {
68 const x = xs[i];
69 r[i] = f(x, i);
70 }
71 return r;
72};
73
74// Unwound implementing other functions in terms of each.
75// The code size is roughly the same, and it should allow for better optimisation.

Callers 1

bindFunction · 0.70

Calls 1

fFunction · 0.50

Tested by

no test coverage detected