Owen Rossi-Keen
Owen Rossi-Keen
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
There's probably plenty of ways to optimize but I'm quite possibly braindead after two hours of monkeying around with it
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
Fobject?
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
And then parse the object through turnObjectIntoFunction before I export my function/object
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
I just give my desired default behavior the _default key
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
This seems to work
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
I figured something out
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
turnObjectIntoFunction(object, options) {
let temp = object._default
? function (args) {
return object._default(args);
}
: {};

let keys = Object.keys(object);

for (let index = 0; index < keys.length; index++) {
let key = keys[index];
let data = object[key];

if (key !== '_default')
temp[key] =
typeof data == 'object' && !Array.isArray(data) && options?.recursive
? this.turnObjectIntoFunction(data)
: data;
}

return temp;
},
turnObjectIntoFunction(object, options) {
let temp = object._default
? function (args) {
return object._default(args);
}
: {};

let keys = Object.keys(object);

for (let index = 0; index < keys.length; index++) {
let key = keys[index];
let data = object[key];

if (key !== '_default')
temp[key] =
typeof data == 'object' && !Array.isArray(data) && options?.recursive
? this.turnObjectIntoFunction(data)
: data;
}

return temp;
},
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
So that I don't need to write a new line for every deeply nested method
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
ekomS – 23-57 Dec 21
Is there any way to nest this assignment within the arrayFunctions function?
16 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
I implemented both
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
Thank you
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
That's what I'm looking for
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
Perfect
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
Makes sense
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
This is how I want to use the function
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
arrayFunctions.sort.truthyFirst(products, (product) => {
return product.metadata.status == 'In Stock';
})
arrayFunctions.sort.truthyFirst(products, (product) => {
return product.metadata.status == 'In Stock';
})
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
The value will always be a boolean
22 replies
RReactiflux
Created by Owen Rossi-Keen on 12/21/2022 in #help-js
✅ – ekomS – 23-35 Dec 21
Well
22 replies