Skip to content

Instantly share code, notes, and snippets.

View slopeofhope81's full-sized avatar

Steve Lim slopeofhope81

View GitHub Profile
@slopeofhope81
slopeofhope81 / reverse function
Created January 23, 2014 16:42
How to write a reverse function on an array that has integers
Do you know that the sort method does not work so well on integers in an array since it is used for strings!
That is something I found out today so then how to use a sort method on an array that has integers? Simply add a
custom function to a sort method as an argument like below!
var arr = [1,100,4,30,5,80]
var compare = function(num1,num2){
if (num1 < num2){
return -1;
}
else if (num1 > num2){
return 1;
@slopeofhope81
slopeofhope81 / gist:8572466
Created January 23, 2014 03:46
Project Euler question #1: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
/*If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
var multiples = function (n) {
var sum = 0;
for (var i = 1; i < n; i++) {
if ((i % 3 == 0) || (i % 5 == 0)) {
sum += i;