This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Looping a triangle' | |
in Eloquent JavaScript Second Edition | |
Chapter 2 Program Structure | |
*/ | |
var output = ""; | |
for(var i = 1; i < 8; i++) { | |
console.log(output += "#"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'FizzBuzz' | |
in Eloquent JavaScript Second Edition | |
Chapter 2 Program Structure | |
*/ | |
for (var i = 1;i < 101;i++) { | |
var output = " "; | |
if (i % 3 == 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Chess board' | |
in Eloquent JavaScript Second Edition | |
Chapter 2 Program Structure | |
*/ | |
var oddRow = "# # # #"; | |
var evenRow = " # # # #"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Minimum' | |
in Eloquent JavaScript Second Edition | |
Chapter 3 Functions | |
*/ | |
function min(a,b) { | |
x = a - b; | |
if (x > 0) { | |
return b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Recursion' | |
in Eloquent JavaScript Second Edition | |
Chapter 3 Functions | |
*/ | |
function isEven(num) { | |
if (num % 2 == 0) { | |
return true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Bean counting' | |
in Eloquent JavaScript Second Edition | |
Chapter 3 Functions | |
*/ | |
function countBs(string) { | |
var str = string.toLowerCase(); | |
var array = str.split(""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'The sum of a range' | |
in Eloquent JavaScript Second Edition | |
Chapter 4 Data Structures: Objects and Arrays | |
*/ | |
function range(first, second, third) { | |
var array = []; | |
if (first < second) { | |
while (first <= second ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Reversing an array' | |
in Eloquent JavaScript Second Edition | |
Chapter 4 Data Structures: Objects and Arrays | |
*/ | |
function reverseArray(array) { | |
var output = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Deep comparison' | |
in Eloquent JavaScript Second Edition | |
Chapter 4 Data Structures: Objects and Arrays | |
*/ | |
function deepEqual(o1, o2) { | |
if(JSON.stringify(o1) === JSON.stringify(o2)) { | |
return true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My answer for exercise 'Flattening' | |
in Eloquent JavaScript Second Edition | |
Chapter 5 Higher-Order Functions | |
*/ | |
console.log([].concat.apply([], arrays)); |
OlderNewer