開発環境
- OS X Mavericks - Apple(OS)
- Safari, Firefox + Firebug, Google Chrome(Webプラウザ、プラグイン)
- BBEdit - Bare Bones Software, Inc. (GUI) , Emacs (CUI) (Text Editor)
- JavaScript (プログラミング言語)
Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 7(Types, Equality, Conversion and All That Jazz: Serious types)、SHARPEN YOUR PENCIL(p.290)を解いてみる。
SHARPEN YOUR PENCIL(p.290)
コード(BBEdit, Emacs)
var findCarInLot = function (car) { var i, max; for (i = 0, max = lot.length; i < max; i += 1) { if (car === lot[i]) { return i; } } }, chevy = { make: 'Chevy', model: 'Bel Air' }, taxi = { make: 'Webville Motors', model: 'Taxi' }, fiat1 = { make: 'Fiat', model: '500' }, fiat2 = { make: 'Fiat', model: '500' }, lot = [chevy, taxi, fiat1, fiat2], output = ''; output += findCarInLot(fiat2) + '\n'; // 3 (not 2) output += findCarInLot(taxi) + '\n'; // 1 output += findCarInLot(chevy) + '\n'; // 0 output += findCarInLot(fiat1); // 2 print(output);
0 コメント:
コメントを投稿