| Server IP : 159.203.156.69 / Your IP : 216.73.216.179 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/array.prototype.flatmap/test/ |
Upload File : |
'use strict';
var inspect = require('object-inspect');
var forEach = require('for-each');
module.exports = function (flatMap, t) {
t.test('callback function', function (st) {
forEach([[], {}, true, false, 42, 'foo', /a/g, null], function (nonFunction) {
st['throws'](
function () { flatMap([], nonFunction); },
TypeError,
inspect(nonFunction) + ' is not a function'
);
});
st.end();
});
t.test('flatMaps', function (st) {
var mapped = flatMap([1, [2], [3, 4]], function (x, i) {
return [x, i];
});
var expected = [1, 0, [2], 1, [3, 4], 2];
st.deepEqual(mapped, expected, 'array is flattened and mapped to tuples of item/index');
st.equal(mapped.length, expected.length, 'array has expected length');
var context = {};
var actual;
flatMap([1], function () { actual = this; }, context);
st.equal(actual, context, 'thisArg works as expected');
st.end();
});
t.test('sparse arrays', function (st) {
var identity = function (x) { return x; };
// eslint-disable-next-line no-sparse-arrays
st.deepEqual(flatMap([, [1]], identity), flatMap([[], [1]], identity), 'an array hole is treated the same as an empty array');
st.end();
});
t.test('test262: staging test from v8', function (st) {
var arr1 = [0, 1, 2, 3];
var f = function (e) {
arr1[4] = 42;
return e;
};
st.deepEqual(flatMap(arr1, f), [0, 1, 2, 3]);
var arr2 = [0, 1, 2, 3];
var g = function (e) {
arr2.length = 3;
return e;
};
st.deepEqual(flatMap(arr2, g), [0, 1, 2]);
st.end();
});
};