2014年9月10日水曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 10(Liberated functions: First Class Functions)、EXERCISE(p.448)を解いてみる。

EXERCISE(p.448)

コード(BBEdit, Emacs)

var checkNotPaid = function (passenger) {
        return !passenger.paid;
    },
    passengers = [ { name: "Jane Doloop", paid: true },
                    { name: "Dr. Evel", paid: true },
                    { name: "Sue Property", paid: false },
                    { name: "John Funcall", paid: true }],
    processPassengers = function (passengers, testFunction) {
        var i,
            max;
        for (i = 0, max = passengers.length; i < max; i += 1) {
            if (testFunction(passengers[i])) {
                return false;
            }
        }
        return true;
    },
    printPassenger = function (passenger) {
        if (checkNotPaid(passenger)) {
            print(passenger.name + ' have not paid.');
        } else {
            print(passenger.name + ' have paid.');
        }
    };

processPassengers(passengers, printPassenger);












						

0 コメント:

コメントを投稿