2017年4月1日土曜日

開発環境

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 5(Fruitful subroutines)の Boolean functions の Exercise.を JavaScript で取り組んでみる。

Boolean functions の Exercise.

コード(Emacs)

let isBetween = (x, y, z) => {
    return x <= y && y <= z;
};
let n = 5;
for (let x = 1; x <= n; x += 1) {
    for (let y = 1; y <= n; y += 1) {
        for (let z = 1; z <= n; z += 1) {
            console.log(`${x} <= ${y} <= ${z}: ${isBetween(x, y, z)}`);
        }
    }
}

入出力結果(Terminal, REPL)

$ node sample_between.js
1 <= 1 <= 1: true
1 <= 1 <= 2: true
1 <= 1 <= 3: true
1 <= 1 <= 4: true
1 <= 1 <= 5: true
1 <= 2 <= 1: false
1 <= 2 <= 2: true
1 <= 2 <= 3: true
1 <= 2 <= 4: true
1 <= 2 <= 5: true
1 <= 3 <= 1: false
1 <= 3 <= 2: false
1 <= 3 <= 3: true
1 <= 3 <= 4: true
1 <= 3 <= 5: true
1 <= 4 <= 1: false
1 <= 4 <= 2: false
1 <= 4 <= 3: false
1 <= 4 <= 4: true
1 <= 4 <= 5: true
1 <= 5 <= 1: false
1 <= 5 <= 2: false
1 <= 5 <= 3: false
1 <= 5 <= 4: false
1 <= 5 <= 5: true
2 <= 1 <= 1: false
2 <= 1 <= 2: false
2 <= 1 <= 3: false
2 <= 1 <= 4: false
2 <= 1 <= 5: false
2 <= 2 <= 1: false
2 <= 2 <= 2: true
2 <= 2 <= 3: true
2 <= 2 <= 4: true
2 <= 2 <= 5: true
2 <= 3 <= 1: false
2 <= 3 <= 2: false
2 <= 3 <= 3: true
2 <= 3 <= 4: true
2 <= 3 <= 5: true
2 <= 4 <= 1: false
2 <= 4 <= 2: false
2 <= 4 <= 3: false
2 <= 4 <= 4: true
2 <= 4 <= 5: true
2 <= 5 <= 1: false
2 <= 5 <= 2: false
2 <= 5 <= 3: false
2 <= 5 <= 4: false
2 <= 5 <= 5: true
3 <= 1 <= 1: false
3 <= 1 <= 2: false
3 <= 1 <= 3: false
3 <= 1 <= 4: false
3 <= 1 <= 5: false
3 <= 2 <= 1: false
3 <= 2 <= 2: false
3 <= 2 <= 3: false
3 <= 2 <= 4: false
3 <= 2 <= 5: false
3 <= 3 <= 1: false
3 <= 3 <= 2: false
3 <= 3 <= 3: true
3 <= 3 <= 4: true
3 <= 3 <= 5: true
3 <= 4 <= 1: false
3 <= 4 <= 2: false
3 <= 4 <= 3: false
3 <= 4 <= 4: true
3 <= 4 <= 5: true
3 <= 5 <= 1: false
3 <= 5 <= 2: false
3 <= 5 <= 3: false
3 <= 5 <= 4: false
3 <= 5 <= 5: true
4 <= 1 <= 1: false
4 <= 1 <= 2: false
4 <= 1 <= 3: false
4 <= 1 <= 4: false
4 <= 1 <= 5: false
4 <= 2 <= 1: false
4 <= 2 <= 2: false
4 <= 2 <= 3: false
4 <= 2 <= 4: false
4 <= 2 <= 5: false
4 <= 3 <= 1: false
4 <= 3 <= 2: false
4 <= 3 <= 3: false
4 <= 3 <= 4: false
4 <= 3 <= 5: false
4 <= 4 <= 1: false
4 <= 4 <= 2: false
4 <= 4 <= 3: false
4 <= 4 <= 4: true
4 <= 4 <= 5: true
4 <= 5 <= 1: false
4 <= 5 <= 2: false
4 <= 5 <= 3: false
4 <= 5 <= 4: false
4 <= 5 <= 5: true
5 <= 1 <= 1: false
5 <= 1 <= 2: false
5 <= 1 <= 3: false
5 <= 1 <= 4: false
5 <= 1 <= 5: false
5 <= 2 <= 1: false
5 <= 2 <= 2: false
5 <= 2 <= 3: false
5 <= 2 <= 4: false
5 <= 2 <= 5: false
5 <= 3 <= 1: false
5 <= 3 <= 2: false
5 <= 3 <= 3: false
5 <= 3 <= 4: false
5 <= 3 <= 5: false
5 <= 4 <= 1: false
5 <= 4 <= 2: false
5 <= 4 <= 3: false
5 <= 4 <= 4: false
5 <= 4 <= 5: false
5 <= 5 <= 1: false
5 <= 5 <= 2: false
5 <= 5 <= 3: false
5 <= 5 <= 4: false
5 <= 5 <= 5: true
$

0 コメント:

コメントを投稿