Message from JavaScript discussions

December 2018

— Still using it

— 

I'm not using arguments[0],arguments[1], arguments[2],
like in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments ?
or does h, s, v does that implicitly?

— Nope, just arguments.length

— Oh wow, I didn't see that

— I should be able to replace that with

s === undefined && v === undefined
, right?

— 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 });

Message permanent page

— That would allow for arbitrary combinations:

HSVtoRGB(3, 2, { v: 40 })
HSVtoRGB({ s: 200, h: 10 }, { v: 20 });

Message permanent page

— 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 😭