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 x = 0, num = 0; | |
while (x<100){ | |
num++; | |
if((num%3) === 0 && (num%5) !== 0 ){ | |
console.log("Fizz"); | |
}else if((num%3) !== 0 && (num%5) === 0){ | |
console.log("Buzz"); | |
}else if((num%3) === 0 && (num%5) === 0){ | |
console.log("FizzBuzz"); | |
}else{ |
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
//size is the dimension of the square grid | |
var size = 8, | |
white = " ", | |
black = "#", | |
rowE = "", | |
rowO = "", | |
grid = ""; | |
//even grid row | |
for ( var x = 0 ; x < size; x++){ | |
if (x % 2 === 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 solution | |
function f(n){ | |
return n > 0 && n % 1 === 0 ? ((1+n)*n)/2 : false; | |
}; | |
//good examples | |
//1 | |
function f(n){ | |
return (parseInt(n) === n && n > 0) ? n*(n+1)/2 : false; | |
}; |
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 solution | |
var paginationText = function(pageNumber, pageSize, totalProducts){ | |
var numOfPages = Math.ceil(totalProducts/pageSize); | |
var initItem = pageNumber*pageSize-(pageSize-1); | |
var endItem; | |
if (pageNumber === numOfPages){ | |
endItem = totalProducts; | |
}else{ | |
endItem = pageSize*pageNumber; | |
}; |
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 example | |
function descendingOrder(n){ | |
var digits = (""+n).split("").sort(function(a, b){return b-a}); | |
digits = digits.join(""); | |
return Number(digits); | |
} | |
//good examples | |
//1 | |
function descendingOrder(n){ |
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 solution using REGEX | |
function toCurrency(price){ | |
return price.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); | |
} | |
//good example | |
function toCurrency(price){ | |
return price.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,'); | |
} |
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 ajax = { | |
load : function() { | |
var xhr; | |
if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest(); | |
else { | |
var versions = ["MSXML2.XmlHttp.5.0", | |
"MSXML2.XmlHttp.4.0", | |
"MSXML2.XmlHttp.3.0", | |
"MSXML2.XmlHttp.2.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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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 shuffle(array) { | |
var m = array.length, t, i; | |
// While there remain elements to shuffle… | |
while (m) { | |
// Pick a remaining element… | |
i = Math.floor(Math.random() * m--); | |
// And swap it with the current element. |
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
//if statement | |
(if ( foo ) { | |
bar = "beta"; | |
} | |
// and... | |
if ( foo ) { | |
bar(); | |
}) | |
//alternative |
OlderNewer