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
| var size = 8; //this is the variable setting | |
| var board = ""; | |
| for (var y = 0; y < size; y++) { | |
| for (var x = 0; x < size; x++) { | |
| if ((x + y) % 2 == 0) | |
| board += " "; | |
| else | |
| board += "#"; |
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
| var number = 0; | |
| for(var i = 1; i<=100; i++){ | |
| number = i; | |
| if(number % 5===0 && number % 3===0) console.log("Fizz Buzz"); | |
| else if(number % 5===0) console.log("Buzz"); | |
| else if(number % 3===0) console.log("Fizz"); | |
| else console.log(number); | |
| } |
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
| // Your code here. | |
| function ifEven(number){ | |
| if (number==0) console.log(true); | |
| else console.log(false); | |
| isEven(number-2); | |
| } |
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
| function countBs(word){ | |
| var sum=0; | |
| for( var i = 0; i < word.length; i++){ | |
| if (word.charAt(i)==="B") sum++; | |
| }; | |
| console.log(sum); | |
| }; | |
| function countChar(word, index){ | |
| var sum=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
| var reverseArray = function(arr) { | |
| var arr2 = []; | |
| for (var i = arr.length - 1; i >= 0; i--) | |
| arr2.push(arr[i]); | |
| return arr2; | |
| }; | |
| var reverseArrayInPlace = function(arr) { | |
| var arr2 = 0; | |
| for (var i = 0; i < arr.length / 2; i++) { | |
| arr2 = arr[i]; |
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
| // Your code here. | |
| function arrayToList(arr){ | |
| var list = null; | |
| for (var i = arr.length-1; i>=0; i--) | |
| list = {value:arr[i], rest:list}; | |
| return list; | |
| } | |
| function listToArray(list){ | |
| var arr=[]; |
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
| // Your code here. | |
| function deepEqual(obj1,obj2){ | |
| if(obj1===obj2) return true; | |
| if (obj1 == null || typeof obj1 != "object" || | |
| obj2 == null || typeof obj2 != "object") | |
| return false; | |
| var propObj1 = 0, propObj2 = 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
| var arrays = [[1, 2, 3], [4, 5], [6]]; | |
| console.log(arrays.reduce(function(a,b) { | |
| return a.concat(b); | |
| })); | |
| // Your code here. | |
| // → [1, 2, 3, 4, 5, 6] |
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
| function average(array) { | |
| function plus(a, b) { return a + b; } | |
| return array.reduce(plus) / array.length; | |
| } | |
| var byName = {}; | |
| ancestry.forEach(function(person) { | |
| byName[person.name] = person; | |
| }); |
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
| function average(array) { | |
| function plus(a, b) { return a + b; } | |
| return array.reduce(plus) / array.length; | |
| } | |
| var century = people(ancestry,function(person){ | |
| return Math.ceil(person.died / 100); | |
| }); | |
| for(var cent in century){ |
OlderNewer