Message from JavaScript discussions
December 2018
— Or would that be bad as well?
Ideally I would perform some sort of reduction on each argument, such as:
function HSVtoRGB(...args) {
const { h, s, v } = args.reduce((acc, cur, i) => {
const keys = Object.keys(acc);
if (typeof cur === 'number') {
return {
...acc,
[keys[i % keys.length]]: cur
};
} else if (typeof cur === 'object') {
return {
h: cur.h || acc.h,
s: cur.s || acc.s,
v: cur.v || acc.v,
}
return acc;
}, { h: 0, s: 0, v: 0 });
— That would allow for arbitrary combinations:
HSVtoRGB(3, 2, { v: 40 })
HSVtoRGB({ s: 200, h: 10 }, { v: 20 });
— OR I would just lock it down
— To only allow numbers
— Wow. Thanks.
Yeah probably the 2nd approach is better o.O
— I'm just trying to get a stackoverflow answer through my linter 😭
— const
function parameters? why not
— Arguments make perf problems when sliced, checking length is okay
— Anyone handled Vue Native here? What's your experience been like?
— Guys, is there such a thing as a actually working powerbank?
— Transmit your opinion right away🤤 folks are too specific digging own holes, i think