@vect/column-mapper
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -25,3 +25,51 @@ 'use strict'; | ||
function columnMapper(mx, fn, l) { | ||
const { | ||
y | ||
} = this; | ||
l = l || mx && mx.length; | ||
const mt = Array(l); | ||
for (let r; --l >= 0 && (r = mx[l].slice());) { | ||
r[y] = fn(r[y], l); | ||
mt[l] = r; | ||
} | ||
return mt; | ||
} | ||
/** | ||
* Return a mapper function that iterate through each element in column indexed by 'y'. | ||
* @param {number} y | ||
* @returns {function(*[][],function(*):*,[number]):*[][]} | ||
* @constructor | ||
*/ | ||
const ColumnMapper = y => columnMapper.bind({ | ||
y | ||
}); | ||
function columnMutate(mx, fn, l) { | ||
const { | ||
y | ||
} = this; | ||
l = l || mx && mx.length; | ||
for (let r; --l >= 0 && (r = mx[l]);) r[y] = fn(r[y], l); | ||
return mx; | ||
} | ||
/** | ||
* Return a mutate function that iterate through each element in column indexed by 'y'. | ||
* @param {number} y | ||
* @returns {function(*[][],function(*):*,[number]):*[][]} | ||
* @constructor | ||
*/ | ||
const ColumnMutate = y => columnMutate.bind({ | ||
y | ||
}); | ||
exports.ColumnMapper = ColumnMapper; | ||
exports.ColumnMutate = ColumnMutate; | ||
exports.mapper = mapper; | ||
exports.mutate = mutate; |
@@ -21,2 +21,48 @@ function mapper(mx, y, fn, l) { | ||
export { mapper, mutate }; | ||
function columnMapper(mx, fn, l) { | ||
const { | ||
y | ||
} = this; | ||
l = l || mx && mx.length; | ||
const mt = Array(l); | ||
for (let r; --l >= 0 && (r = mx[l].slice());) { | ||
r[y] = fn(r[y], l); | ||
mt[l] = r; | ||
} | ||
return mt; | ||
} | ||
/** | ||
* Return a mapper function that iterate through each element in column indexed by 'y'. | ||
* @param {number} y | ||
* @returns {function(*[][],function(*):*,[number]):*[][]} | ||
* @constructor | ||
*/ | ||
const ColumnMapper = y => columnMapper.bind({ | ||
y | ||
}); | ||
function columnMutate(mx, fn, l) { | ||
const { | ||
y | ||
} = this; | ||
l = l || mx && mx.length; | ||
for (let r; --l >= 0 && (r = mx[l]);) r[y] = fn(r[y], l); | ||
return mx; | ||
} | ||
/** | ||
* Return a mutate function that iterate through each element in column indexed by 'y'. | ||
* @param {number} y | ||
* @returns {function(*[][],function(*):*,[number]):*[][]} | ||
* @constructor | ||
*/ | ||
const ColumnMutate = y => columnMutate.bind({ | ||
y | ||
}); | ||
export { ColumnMapper, ColumnMutate, mapper, mutate }; |
{ | ||
"name": "@vect/column-mapper", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A debugging tool", | ||
@@ -33,3 +33,3 @@ "main": "dist/index.cjs.js", | ||
"homepage": "https://github.com/hoyeungw/vect#readme", | ||
"gitHead": "36e42f9ffcac1f1214dcd09fd98ee1130f35eaf2" | ||
"gitHead": "6d6f9624d5516ae3b57214985feb10f35a4b0e40" | ||
} |
6039
111