1.0.0 • Published 2 years ago

compact-func v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

FUNCTION-FACILITATOR

METHODS:

  1. Filter
  2. Map
const compactFunc = require("compact-func");

let equal = compactFunc.returnEqualItemInArr([1, 2, 3], 3);
console.log(equal); //output: [3]

returnEqualItemInArr(arr, target)

Function that filters through an array (first argument) of items and returns the match to parameter passed (second argument):

USAGE EXAMPLE:

console.log(returnEqualItemInArr(["one", "two", "three"], "two"));

returnNotEqualItemInArr(arr, target)

Function that filters through an array (first argument) of items and returns all BUT the match to parameter passed (second argument):

USAGE EXAMPLE:

console.log(returnNotEqualItemInArr(["one", "two", "three"], "two"));

returnObjEqualInArr(arr, par, target)

Function that filters through an array of objects (first argument) and returns the match to target parameter passed (Third argument). The second argument is the 'key' property of the object:

USAGE EXAMPLE:

console.log(
  returnObjEqualInArr(
    [{ name: "one" }, { name: "two" }, { name: "three" }],
    "name",
    "two"
  )
);

returnObjNotEqualInArr(arr, par, target)

Function that filters through an array of objects (first argument) and returns all BUT the match to target parameter passed (Third argument). The second argument is the 'key' property of the object:

USAGE EXAMPLE:

console.log(
  returnObjNotEqualInArr(
    [{ name: "one" }, { name: "two" }, { name: "three" }],
    "name",
    "two"
  )
);

copyOriginalArrAndDoThisToEach(arr, doFunc)

Function that Maps through an array (first argument) and returns a copy of the original array after running the function passed (second argument).

USAGE EXAMPLE:

console.log(copyOriginalArrAndDoThisToEach([1, 2, 3], (item) => item * 2));