lundi 16 novembre 2020

Is there a way to assign a value to a thing based on where it appears in a list?

I have six letters [a,b,c,d,e,f] and two users [bob,bender]. They both have a different arrangement of the letters that represents them, think personality score-ish. Bob is [e,f,c,b,a,d] and Bender is [b,a,d,f,e,c].

I also have a chart to put these on. Each letter, in order, has it's own bar on the chart and the ticks go up to 6.

Depending on where in the list the letter appears it has a number value assigned. The first letter gets a value of 6, the second a value of 5, and so on.

The final array needs to be in abc order, but with the correct value for each letter. Example: Bob would end up with [2,3,4,1,6,5].

How would you do this?

The only way I can figure is a ton of if statements and I'm trying to see if there's a better way.

I'm still new to Javascript.

Aucun commentaire:

Enregistrer un commentaire