associateBy and groupBy function helps to build the maps from the elements of a collection indexed by the specified key.
keySelector: The key is defined in the keySelector parameter.
valueSelector: We can also specify an optional valueSelector to define what will be stored in the value of the map element, in case of not specifying the same it will consider the complete object as a value.
The difference between associateBy and groupBy is about how they process the objects with the respective key
associateBy - It uses the last suitable element as the result value.
groupBy - it produces the list of all suitable elements and puts it in the result value(s).
P.S. The returned map preserves the entry iteration order of the original collection.