Please can someone help with this question, I'm a bit stuck.
Write a function which will accept a list corresponding to a mark list, where each entry in the mark list has the form {test number, first name, family name, mark}
or, if a mark is missing, {test number, first name, family name}
and which will return a new list of consolidated marks where each list member has the form {first name, family name, test1_mark, test2_mark, ...}
in alphabetical order of first names, for example, {{Barak, Obama, 22}, {..., ..., ...}, ...}
.
Each list member should only contain test marks for tests attempted for each person (and so each member may have a different length). Your function should make use of a rule using appropriate patterns, and will probably need to use the Map
and Rest
functions and a function to sort by the first name.
marks = {{1, David, Cameron, 18}, {2, Donald, Trump, 8}, {3, David, Cameron, 11},
{1, Barak, Obama, 22}, {1, Boris, Johnson}, {2, Boris, Johnson},
{3, Boris, Johnson}, {4, David, Cameron, 17}};
So far I have created a rule, but it does not work on cases where there is no mark.
list = {z_, x_, y_, v_} -> {x, y, v};
uFun[{z_,x_,y_,v_}]:={x,y,v}
anduFun[{z_,x_,y_}]:={x,y}
. ThenuFun @ mark
should make the trick. $\endgroup$