I have this random score (a number) between 0-72.
Each score number has a key number that I have set. (look below)
I need to retrieve the key number by using a function.
Example:
function scoreToKey(score) {
// the mystery code goes here
return PERCENTAGE;
}
scoreToKey(100); // needs to return 100
scoreToKey(72); // needs to return 100
scoreToKey(50); // needs to return 39
scoreToKey(44); // needs to return 4
scoreToKey(29); // needs to return -92
scoreToKey(12); // needs to return -100
scoreToKey(0); // needs to return -100
I figure you need to use arrays somehow but I can't figure out how.
These are my key values:
score | key
72 100
71 99
70 98
69 97
68 96
67 95
66 94
65 92
64 90
63 87
62 84
61 81
60 78
59 75
58 72
57 69
56 65
55 61
54 57
53 53
52 49
51 44
50 39
49 34
48 28
47 22
46 16
45 10
44 4
43 -2
42 -8
41 -16
40 -24
39 -32
38 -40
37 48
36 56
35 -64
34 -70
33 -76
32 -82
31 -68
30 -90
29 -92
28 -94
27 -96
26 -98
25 -99
1-24 -100
I would really appreciate your help, I can't figure this out and I also don't know what to search for really.
By the way, your code can be in ES6, I don't mind :) Thanks in advance