開発環境
- 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 4(Putting Some Order in Your Data: Arrays)、SHARPEN YOUR PENCIL(p.153)を解いてみる。
SHARPEN YOUR PENCIL(p.153)
コード(BBEdit, Emacs)
var output = '', scores = [60, 50, 60, 58, 54, 54, 58, 50, 52, 54, 48, 69, 34, 55, 51, 52, 44, 51, 69, 64, 66, 55, 52, 61, 46, 31, 57, 52, 44, 18, 41, 53, 55, 61, 51, 44], highScore = - Infinity, bestsolutions = [], i, max; for (i = 0, max = scores.length; i < max; i += 1) { output += 'Bubble solution #' + i + ' score: ' + scores[i] + '\n'; if (scores[i] > highScore) { highScore = scores[i]; } } output += 'Bubbles tests: ' + max + '\n'; output += 'Highest bubble score: ' + highScore + '\n'; for (i = 0, max = scores.length; i < max; i += 1) { if (highScore === scores[i]) { bestsolutions.push(i); } } output += 'Best solutions: ' + bestsolutions + '\n'; print(output);
0 コメント:
コメントを投稿