This test is not meant to be easy, but on the other hand it is one that, I feel, anyone who calls themselves a professional
computer programmer ought to be able to do. The language used is JavaScript, however the intention is that familiarity
with any modern, high-level language should be all that is needed, with anything Java-specific being explained as
required.
There are three sections. The later sections will be exposed upon successful completion of the earlier. No feedback is
sent except at the end, where you can, optionally, e-mail your code snippets, and any comments you may have, to the Test Master.
Section 1 - data comparison.
The data we will be trying to process will all be in the form of strings. The problem is that these are also used
to represent numbers, and dates. String comparison with <, =, >, etc. though produces a lexical sort,
meaning that, for example, "12" is less than "2", and "28 Aug 1959" is greater than "1 Jan 2025". So we need a function that
will see if a string represents a number or a date, and if so, return that value for comparison instead of the string.
With that in mind, make the appropriate changes to the function below. Things you need to know: "Number(x)" and "Date.parse(x)"
are built-in functions that try to interpret a string as respectively a number and a date (or date/time - the latter returning a
number which is the number of milliseconds since midnight on January 1, 1970), both returning "NaN" ("not a number") if they
are unable to do so. The function "isNaN(x)" may be used to test for a "NaN" value.
Section 2 - sorting.
Moroccan National Football Team
October 2025
November 2025
Number
Name
DOB
Position
12
Munir Mohamedi
10 May 1989
Goalkeeper
1
Yassine Bounou
5 Apr 1991
Goalkeeper
18
Jawad El Yamiq
29 Feb 1992
Defender
15
Mohamed Chibi
21 Jan 1993
Defender
20
Ayoub El Kaabi
25 Jun 1993
Forward
6
Adam Masina
2 Jan 1994
Defender
5
Nayef Aguerd
30 Mar 1996
Defender
4
Sofyan Amrabat
21 Aug 1996
Midfield
19
Youssef En-Nesyri
1 Jun 1997
Forward
26
Anas Bach
10 Feb 1998
Midfield
3
Youssef Belammari
20 Sep 1998
Defender
2
Achraf Hakimi
4 Nov 1998
Defender
10
Brahim Díaz
3 Aug 1999
Forward
21
Amine Adli
10 May 2000
Forward
24
Souffian El Karouani
19 Oct 2000
Defender
22
El Mehdi Al Harrar
30 Nov 2000
Goalkeeper
11
Ismael Saibari
28 Jan 2001
Midfield
8
Neil El Aynaoui
2 Jul 2001
Midfield
17
Abde Ezzalzouli
17 Dec 2001
Forward
14
Oussama Targhalline
20 May 2002
Midfield
9
Hamza Igamane
2 Nov 2002
Forward
25
Omar El Hilali
12 Sep 2003
Defender
16
Ilias Akhomach
16 Apr 2004
Forward
23
Bilal El Khannouss
10 May 2004
Midfield
13
Eliesse Ben Seghir
16 Feb 2005
Midfield
7
Chemsdine Talbi
9 May 2005
Forward
Number
Name
DOB
Position
1
Yassine Bounou
5 Apr 1991
Goalkeeper
2
Youssef Belammari
20 Sep 1998
Defender
3
Noussair Mazraoui
14 Nov 1997
Defender
4
Sofyan Amrabat
21 Aug 1996
Midfield
5
Adam Masina
2 Jan 1994
Defender
6
Romain Saïss
26 Mar 1990
Defender
7
Chemsdine Talbi
9 May 2005
Forward
8
Azzedine Ounahi
19 Apr 2000
Midfield
9
Soufiane Rahimi
2 Jun 1996
Forward
10
Brahim Díaz
3 Aug 1999
Forward
11
Ismael Saibari
28 Jan 2001
Midfield
12
Munir Mohamedi
10 May 1989
Goalkeeper
13
Eliesse Ben Seghir
16 Feb 2005
Midfield
14
Oussama Targhalline
20 May 2002
Midfield
15
Mohamed Chibi
21 Jan 1993
Defender
16
Ilias Akhomach
16 Apr 2004
Forward
17
Abde Ezzalzouli
17 Dec 2001
Forward
18
Jawad El Yamiq
29 Feb 1992
Defender
19
Youssef En-Nesyri
1 Jun 1997
Forward
20
Ayoub El Kaabi
25 Jun 1993
Forward
21
Hamza Igamane
2 Nov 2002
Forward
22
Bilal El Khannouss
10 May 2004
Midfield
23
Neil El Aynaoui
2 Jul 2001
Midfield
24
Sofiane Diop
9 Jun 2000
Forward
25
Anass Salah-Eddine
18 Jan 2002
Defender
26
Abdelhamid Aït Boudlal
16 Apr 2006
Defender
Double-clicking the column headers will reverse the order of the list, but what we want is
for it to sort the list on that particular column instead.
Just two functions are provided to access the data:
exchRows(tbl, row1, row2)
exchanges row1 and row2
compareRows(tbl, row1, row2, sortCols)
compares row1 and row2, returning -1, 0, or 1
according to whether row1 is less than, equal to, or greater than row2
Numbering of rows is from 1 to n, and you need to sort from smaller to greater. The variable sortCols
is a record of the last four columns double clicked, numbering columns from 1 to 4. This should be
passed to compareRows without further processing. Double-clicking twice on a column header changes the
value to minus the value, which is a signal to reverse the comparison, causing the data to
come out in reverse order. Historical column numbers form the secondary, tertiary, etc. keys
for the sort.
Error Label
Section 3 - differencing.
The function changesInTeam receives zero-based, sorted arrays of the players’ names from which you need
to produce a zero-based array whose elements are, respectively, a comma-separated list of the players dropped, and
a comma-separated list of the players added. You can get the number of elements of an array with .length. If
the array index exceeds the bounds then the value undefined will be returned rather than an error, and this value
can be tested for. Array.push(elem) can be used to simultaneously enlarge the array by one and
make the last element equal to <elem>.
Players dropped:
Players added:
Final section - send code snippets / comments.
Well done for getting this far! In my humble opinion, this kind of detailed work, where you have to really think about what you are doing
is what programming is all about, and what makes it interesting. Now you can