Inspired by this chat message
Your task will be to take a word and find the average position of its letters on the keyboard as a letter.
Since layouts vary from keyboard to keyboard, we will be using a standard based of of my own keyboard in this question.
The keyboard has 3 rows, the top row from left to right contains the keys
The second row contains the letters
The final row contains
Each letter is 1 unit horizontal from its neighbor to the left. This means that
W is 1 away from
E is 1 away from
W and so on.
The keys at the beginning of each row have the positions:
Q : 0,0 A : 1/3,1 Z : 2/3,2
This means that the rows are separated one unit vertically and the bottom two rows are shifted by a third from the row above them.
You should take a word as input and output the letter that is closest to the average position of the letters in its word. The average of a set of vectors is
(average x value, average y value)
When two keys are equidistant from the average you may output either as the "closest" key.
This is code-golf so answers will be scored in bytes with fewer bytes being better.
Let's calculate the average of
We convert each letter to a vector
A -> (1/3,1) P -> (9,0) L -> (8 1/3,1)
We add these up the three vectors to get
(17 2/3, 2). We then divide each coordinate by 3 (The number of letters in the word) to get
(5 8/9, 2/3).
The closest letter to
(5 8/9, 2/3) is
(6 1/3,1) so our result is
APL -> J TEXT -> R PPCG -> J QQQQ -> Q ZZZZ -> Z PPPP -> P MMMM -> M QQSS -> A or W