jsmp-infra-plotnikov
Version:
jsmp test package that contains some mutations
30 lines (22 loc) • 580 B
JavaScript
import { isArray } from 'lodash';
const operationTypes = {
Reverse: 'reverse'
};
const reverseArray = array => array.reverse();
const operationToActionMap = new Map([
[operationTypes.Reverse, reverseArray]
]);
export default function transformArray(array, operation) {
try {
if (!isArray(array)) {
return null;
}
const isSupportedOperation = Object.values(operationTypes).includes(operation);
if (!isSupportedOperation) {
return array;
}
return operationToActionMap.get(operation)(array);
} catch (e) {
console.log(e);
}
}