@nknahom/lotide
Version:
Lotide is mini clone of the Lodash (https://lodash.com) library for learning JavaScript. What is Lodash? Lodash is a library that makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.
14 lines (12 loc) • 364 B
JavaScript
const middle = function (array) {
if (array.length === 1 || array.length === 2) {
return [];
} else if (array.length % 2 === 0) {
return array.splice(Math.floor((array.length - 1) / 2), 2);
} else if (array.length % 2 !== 0) {
return array.splice(Math.floor((array.length - 1) / 2), 1);
} else {
return [];
}
};
module.exports = middle;