array_helperz v1.3.30
array_helperz
Instructions:
npm install array_helperz
const array_helperz = require('array_helperz')
If utilizing in html...:
<script src="./node_modules/array_helperz/index.js"></script>
<script>
$(()=> {
const output = array_helperz.method(parameter)
})
</script>
const arrz = require("array_helperz")
let arr = [{
title: 'I want to be free. Free to live, and to find my own way, to love, or to be alone, but at least it is my choice, and I am so tired of not having choices, so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived, which is no life at all.',
status: 'to do',
date: new Date(2020, 1, 1),
id: 1
},
{
title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity, and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
status: 'doing',
date: new Date(2021, 1, 1),
id: 2
},
{
title: 'But a life without art, without wonder, without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
status: 'doing',
date: new Date(2022, 1, 1)
id: 3
}
]
let arr2 = [{
"user_id": 4,
"task_id": 1,
"tag": "quote",
"snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
"hourglass_id": 4,
"id": 1
}, {
"user_id": 4,
"task_id": 1,
"tag": "quote",
"snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
"hourglass_id": 4,
"id": 2
}]
function removeObj(x) {
if (x.id === 2) {
return true;
}
}
array_helperz.filterWithFuncObjectOrString(arr, { status: "to do" })
array_helperz.trimArr(arr) // trims if value is string
array_helperz.countByCondition(arr, "id", 1) // returns number
array_helperz.search(arr, stringValue) // returns arr
array_helperz.filterItems(arr, stringKey, stringValue) // search for specific key
array_helperz.filterValues(arr, stringValue, arrOfKeys)
array_helperz.sortAsc(arr, stringKey)
array_helperz.sortDesc(arr, stringKey)
array_helperz.contains(arr, stringKey, stringValue)
array_helperz.doesNotContain(arr, stringKey, stringValue)
array_helperz.group(arr, stringKey)
array_helperz.getUnique(arr, stringKey)
array_helperz.intersection(arr, arr2)
array_helperz.mergeByKeys({data: arr, key: "id" }, {data: arr2, key: "id" })
array_helperz.makeChildOfAnother({data: arr, key: "id" }, {data: arr2, key: "id" })
array_helperz.getOneMakeChildOfAnother({data: arr, key: "id", value: 2 }, {data: arr2, key: "id", value: 3 })
array_helperz.removeByFunction(arr, function sort(x) {if (x.id === 1 {return true})})
array_helperz.replaceKey(arr, originalKey, replaceKey)
Functions
filterWithFuncObjectOrString(array, object, value) ⇒ any
Kind: global function
Date: 2022-03-17
Author: zen-out
Param | Type | Description |
---|---|---|
array | array | |
object | object | |
value | array | = undefined |
Example
let arrTwo = [
{ name: 'Because we loved each other too much and found each other too interesting. And I love that about humanity, and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.', status: 'doing', problem_id: 2, id: 1 },
{ name: 'I want to be free. Free to live, and to find my own way, to love, or to be alone, but at least it is my choice, and I am so tired of not having choices, so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived, which is no life at all.', status: 'doing', problem_id: 2, id: 2 },
{ name: 'But a life without art, without wonder, without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.', status: 'to do', problem_id: 2, id: 3 }
]
function getToDo(object) {
if (object.status === "to do") {
return object;
}
}
let func = filterWithFuncObjectOrString(arrTwo, getToDo)
let obj = filterWithFuncObjectOrString(arrTwo, { status: "to do" })
let keyValue = filterWithFuncObjectOrString(arrTwo, "status", "to do")
let key = filterWithFuncObjectOrString(arrTwo, "status")
trimArr(arr) ⇒ array
trims array values
Kind: global function
Date: 2021-12-19
Author: zen-out
Author: zen-out
Param | Type |
---|---|
arr | array |
countByCondition(array, key, value) ⇒ number
Kind: global function
Returns: number - of objects that meet that condition
Date: 2022-02-17
Author: zen-out
Param | Type |
---|---|
array | array |
key | string |
value | string |
Example
const array_helperz = require("array_helperz")
let sampleInput = [{
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
whatshouldbe: "it should be easier to develop as a whole application but that's actually quite difficult - so segment each component and make sure you test utilizing good practices",
whatactuallyis: "there's no like, database of previous problems and how people solved them, right? also, what is your current process",
hypothesis: "like, what if i wanted to start my own business, how would i do that?",
plan: "test better, when you develop, i think it would also be great actually to have an effectiveness scale - what one task really helped you?"
}, { status: "doing", problem: "we need to focus on one thing at a time", whatshouldbe: "we should be able to do that easily", whatactuallyis: "its quite difficult", hypothesis: "develop modules", plan: "make things very clear and simple" }]
let output = array_helperz.countByCondition(sampleInput, "status", "to do")
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)
search(array, string) ⇒ array
Kind: global function
Date: 2022-03-18
Author: zen-out
Param | Type |
---|---|
array | array |
string | string |
Example
var data = [{
"id": "1",
"name": "Ali",
"BOD": "29/10/2055",
"type": "primary",
"email": null,
"mobile": "010100000000",
"notes": ["note1", "note2.nett", "note3"]
},
{
"id": "2",
"name": "Tie",
"BOD": "29/10/2055",
"type": "primary",
"email": "b@v.net",
"mobile": "0100000000",
"notes": ["note4", "note5", "note6"]
}
];
// search examples .
console.log("found", search(data, ".net")); //expected data[0] data[1]
filterValues(array, keyword, arrOfKeys) ⇒ array
Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out
Param | Type |
---|---|
array | array |
keyword | string |
arrOfKeys | array |
Example
const array_helperz = require("array_helperz")
let sampleInput = [{
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
whatshouldbe: "it should be easier to develop as a whole application but that's actually quite difficult - so segment each component and make sure you test utilizing good practices",
whatactuallyis: "there's no like, database of previous problems and how people solved them, right? also, what is your current process",
hypothesis: "like, what if i wanted to start my own business, how would i do that?",
plan: "test better, when you develop, i think it would also be great actually to have an effectiveness scale - what one task really helped you?"
}, { status: "doing", problem: "we need to focus on one thing at a time", whatshouldbe: "we should be able to do that easily", whatactuallyis: "its quite difficult", hypothesis: "develop modules", plan: "make things very clear and simple" }]
let output = array_helperz.filterValues(sampleInput, "segment", ["problem"])
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)
sortAsc(array, key) ⇒ array
Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out
Param | Type | Description |
---|---|---|
array | array | |
key | string | to sort by |
Example
const array_helperz = require("array_helperz")
let sampleInput = [{
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.sortAsc(sampleInput, "created", "date")
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)
sortDesc(array, key) ⇒ array
Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out
Param | Type | Description |
---|---|---|
array | array | |
key | string | of object |
Example
const array_helperz = require("array_helperz")
let sampleInput = [{
seconds: 500,
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { seconds: 1000, created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.sortDesc(sampleInput, "seconds", "integer")
console.log("🚀 ~ file: playground.js ~ line 11 ~ output", output)
contains(array, property, value) ⇒ array
Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out
Param | Type |
---|---|
array | array |
property | string |
value | string |
Example
const array_helperz = require("array_helperz")
let sampleInput = [{
seconds: 500,
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { seconds: 1000, created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.contains(sampleInput, "seconds", 500)
doesNotContain(array, property, value) ⇒ array
Kind: global function
Returns: array - of objects
Date: 2022-02-17
Author: zen-out
Param | Type |
---|---|
array | array |
property | string |
value | string |
Example
const array_helperz = require("array_helperz")
let sampleInput = [{
seconds: 500,
created: new Date(2020, 12, 1),
status: "to do",
problem: "we actually solve our problems best by looking at how other people solved them - segment each feature",
}, { seconds: 1000, created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" }]
let output = array_helperz.doesNotContain(sampleInput, "seconds", 500)
group(data, groupByCondition) ⇒ array
- @example const array_helperz = require("array_helperz") let sampleInput = { seconds: 500, created: new Date(2020, 12, 1), status: "to do", problem: "we actually solve our problems best by looking at how other people solved them - segment each feature", }, { seconds: 1000, created: new Date(2019, 12, 1), status: "doing", problem: "we need to focus on one thing at a time" } let output = array_helperz.group(sampleInput, "status") console.log("🚀 ~ file: playground.js ~ line 9 ~ output", output)
Kind: global function
Date: 2022-03-06
Author: zen-out
Param | Type |
---|---|
data | array |
groupByCondition | string |
getUnique(arr, key) ⇒ any
Kind: global function
Date: 2022-03-18
Author: zen-out
Param | Type |
---|---|
arr | any |
key | any |
Example
let testArr = [{
id: 1,
hello: "whatsup"
},
{
id: 2,
hello: "whatsup"
},
{
id: 1,
hello: "whatsup"
},
]
export function testUnique() {
let newArr = getUnique(testArr, "id")
console.log(newArr)
}
intersection(nums1, nums2) ⇒ any
Kind: global function
Date: 2022-03-22
Author: zen-out
Param | Type |
---|---|
nums1 | any |
nums2 | any |
Example
let expected_keys =["hello"]
let actual_keys =["hello", "whatsup"]
let merged = intersection(expected_keys, actual_keys)
merged will be ["hello"]
mergeByKeys(arr, object) ⇒ any
Kind: global function
Date: 2022-03-15
Author: zen-out
Param | Type | Description |
---|---|---|
arr | any | |
object | object | {data: arr, key: "problem_id"} -> reference to the joining to arr |
Example
let arr1Child2 = { data: arr, key: "id" }
let arr22 = {
data: arr2,
key: "id",
}
let merged2 = array_helperz.mergeByKeys(arr1Child2, arr22)
makeChildOfAnother({data:, {data:) ⇒ array
Kind: global function
Date: 2022-03-15
Author: zen-out
Param | Type | Description |
---|---|---|
{data: | object | arr, key: "id" } |
{data: | object | arr2, key: "id" } |
Example
let arrOne = [{
title: 'I want to be free. Free to live, and to find my own way, to love, or to be alone, but at least it is my choice, and I am so tired of not having choices, so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived, which is no life at all.',
status: 'to do',
id: 1
},
{
title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity, and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
status: 'doing',
id: 2
},
{
title: 'But a life without art, without wonder, without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
status: 'doing',
id: 3
}
]
let arrTwo = [
{ name: 'Whatever', status: 'doing', problem_id: 2, id: 1 },
{ name: 'is', status: 'doing', problem_id: 2, id: 2 },
{ name: 'people', status: 'to do', problem_id: 2, id: 3 }
]
let arr1 = { data: arrOne, key: "id" }
let arr2 = { data: arrTwo, key: "problem_id" }
let result = makeChildOfAnother(arr1, arr2)
console.log(result)
output
[
{
title: 'I want to be free. Free to live, and to find my own way, to love, or to be alone, but at least it is my choice, and I am so tired of not having choices, so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived, which is no life at all.',
status: 'to do',
id: 1,
child: []
},
{
title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity, and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
status: 'doing',
id: 2,
child: [ [Object], [Object], [Object] ]
},
{
title: 'But a life without art, without wonder, without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
status: 'doing',
id: 3,
child: []
}
]
getOneMakeChildOfAnother({data:, {data:) ⇒ array
Kind: global function
Date: 2022-03-15
Author: zen-out
Param | Type | Description |
---|---|---|
{data: | object | arr, key: "id", value: 2 } |
{data: | object | arr2, key: "id", value: 3 } |
Example
let arrOne = [{
title: 'I want to be free. Free to live, and to find my own way, to love, or to be alone, but at least it is my choice, and I am so tired of not having choices, so scared of the years rushing past beneath my feet. I do not want to die as I’ve lived, which is no life at all.',
status: 'to do',
id: 1
},
{
title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity, and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
status: 'doing',
id: 2
},
{
title: 'But a life without art, without wonder, without beautiful things—she would go mad. She has gone mad. What she needs are stories. Stories are a way to preserve one’s self. To be remembered. And to forget.',
status: 'doing',
id: 3
}
]
let arrTwo = [
{ name: 'Whatever', status: 'doing', problem_id: 2, id: 1 },
{ name: 'is', status: 'doing', problem_id: 2, id: 2 },
{ name: 'people', status: 'to do', problem_id: 2, id: 3 }
]
let arr1GetOne = { data: arrOne, key: "id", value: 2 }
let arr2GetOne = { data: arrTwo, key: "problem_id", value: 2 }
let result2 = getOneMakeChildOfAnother(arr1GetOne, arr2GetOne)
console.log(result2)
output
[
{
title: 'Because we loved each other too much and found each other too interesting. And I love that about humanity, and in fact it’s the very reason I root for us to survive—because we are so stupid about each other.',
status: 'doing',
id: 2,
child: [ [Object], [Object], [Object] ]
}
]
removeByFunction(arr, func) ⇒ array
Kind: global function
Date: 2022-03-22
Author: zen-out
Param | Type |
---|---|
arr | array |
func | function |
Example
let types = [{
"user_id": 4,
"task_id": 1,
"tag": "quote",
"snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
"hourglass_id": 4,
"id": 1
}, {
"user_id": 4,
"task_id": 1,
"tag": "quote",
"snippet": "be more selfish with your time. this is your life. reach your own goals. be more confident in yourself, you got this. i want cyrus on my team",
"hourglass_id": 4,
"id": 2
}]
function removeObj(x) {
if (x.id === 2) {
return true;
}
}
array_helperz.removeByFunction(arr, func)
replaceKey(arr, originalKey, replaceKey) ⇒ array
replaceKey(arr, originalKey, replaceKey)
Kind: global function
Date: 2022-03-23
Author: zen-out
Param | Type |
---|---|
arr | array |
originalKey | string |
replaceKey | string |
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago