# map - lodash, ramda, .map, and ramda's internal _map (v3)

## Description

10_000 rows of Math.floor(Math.random() * 1000) map x => x * Math.floor(Math.random() * 1000)

Why do this? better for collecting multiple runs to look at a standard deviation

## Preparation HTML

``````<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.29.1/ramda.min.js" integrity="sha512-PVSAmDFNqey8GMII8s9rjjkCFvUgzfsfi8FCRxQa3TkPZfdjCIUM+6eAcHIFrLfW5CTFAwAYS4pzl7FFC/KE7Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>``````

## Setup

``````const arr = Array(10_000)
.fill(undefined)
.map((_, i) => i);

// copy of ramda internal
function _ramdaMap(fn, functor) {
var idx = 0;
var len = functor.length;
var result = Array(len);
while (idx < len) {
result[idx] = fn(functor[idx]);
idx += 1;
}
return result;
}

// put forOf and for in functions for consistency
function forOfPush(a) {
const nextArr = [];
for (const v of a) {
nextArr.push(v * Math.floor(Math.random() * 1000));
}
return nextArr;
}

function forISet(a) {
const nextArr = Array(a.length);
for (let i = 0; i < a.length; i++) {
nextArr[i] = a[i] * Math.floor(Math.random() * 1000);
}
return nextArr;
}
``````

## Test runner

Testing in
TestOps/sec
lodash map
``_.map(arr, x => x * Math.floor(Math.random() * 1000));``
ramda map
``R.map(x => x * Math.floor(Math.random() * 1000), arr);``
array#map
``arr.map(x => x * Math.floor(Math.random() * 1000));``
ramda map curried
``R.map(x => x * Math.floor(Math.random() * 1000))(arr);``
``_ramdaMap(x => x * Math.floor(Math.random() * 1000), arr);``
``forOfPush(arr);``
``forISet(arr);``