Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It sounds like you need to implement a function which performs these tasks:</p> <ol> <li><p><strong>Parsing the input</strong>: the string must be parsed into a list of objects with "date" and "title" properties. Try matching the "YYYY-MM-DD" date format with a regular expression and building a Date object with its constructor.</p></li> <li><p><strong>Filtering the data</strong>: the objects should be rejected if older than the current time and sorted by date in increasing order (oldest to newest). Dates can be compared and lists can be sorted natively in JavaScript.</p></li> <li><p><strong>Formatting the output</strong>: the objects should be returned as a list of strings with the desired date format. Try outputting the date by building a string from its month, date, and year getters.</p></li> </ol> <p>You could, of course, use libraries for various tasks like date handling but using pure JavaScript should be simple enough. For example:</p> <pre><code>&lt;script language="javascript"&gt; var parseFeed = function(str, now) { var regex=/^(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d) (.*)$/ , input=str.split(/\n/).sort(), len=input.length , output=[], now=now||new Date(), d, m; for (i=0; i&lt;len; i++) { if (m = input[i].match(regex)) { d = new Date(m[1], m[2]-1, m[3], m[4], m[5], m[6]); if (d &gt;= now) { output.push([m[2], m[3], m[1]].join('-') + ' ' + m[7]); } } } return output; // An array of sorted, yet-to-come, formatted events. }; var input = "" + "2011-02-19 00:00:00 event0 title here\n" + "2011-04-19 00:00:00 event1 title here\n" + "2011-04-22 00:00:00 event2 title here\n" + "2011-05-25 00:00:00 event3 title here\n" + "2011-04-13 00:00:00 event4 title here\n" + "2011-12-13 00:00:00 event5 title here\n"; var april12 = new Date(2011, 3, 21) , output = parseFeed(input, april21); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload