2017年4月13日木曜日

開発環境

Think Perl 6: How to Think Like a Computer Scientist (Laurent Rosenfeld(著)、Allen B. Downey(著)、Oreilly & Associates Inc)のPart 1(Starting with the basics)、Chapter 7(Strings)の Boolean functions の Putting it all together、Extracting dates の Exercises.を JavaScript で取り組んでみる。

Putting it all together、Extracting dates の Exercises.

コード(Emacs)

HTML5

<button id="run0">run</button>
<button id="clear0">clear</button>
<pre id="output0"></pre>

<script src="sample_dates.js"></script>

JavaScript

let input0 = document.querySelector('#word0'),
    btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    pre0 = document.querySelector('#output0'),
    p = (x) => pre0.textContent += x + '\n';

let output = () => {
    let s1 = 'Christmas : 25/12/2016.',
        s2 = 'Christmas : 2016 12, 25.';

    let result1 = s1.match(/([0-2]\d|3[0-1])\/(0[1-9]|1[0-2])\/(\d{4})/);
    result1.forEach((s) => p(s));

    let result2 = s2.match(/(\d{4})\s+(0[1-9]|1[0-2]),\s*([0-2]\d|3[0-1])/);
    result2.forEach((s) => p(s));
};
    

btn0.onclick = output;
btn1.onclick = () => {
    pre0.textContent = '';
};

output();










 
						

0 コメント:

コメントを投稿

Comments on Google+: