[Dr. Chris Oakley's Home Page]

Programming Test

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.