This file contains 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 csv is the CSV file with headers | |
function csvJSON(csv){ | |
var lines=csv.split("\n"); | |
var result = []; | |
var headers=lines[0].split(","); | |
for(var i=1;i<lines.length;i++){ |
This file contains 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
//Write a program that would print all the numbers from 1 to 255 | |
var numbers = function(){ | |
for(var i = 1 ; i > 256; i++){ | |
console.log(i); | |
} | |
} |
This file contains 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
//Write a program that would print all the odd numbers from 1 to 1000 | |
for(var i=1; i<=1000; i=i+2){ | |
console.log(i); | |
} |
This file contains 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
//Write a program that would print the sum of all the odd numbers from 1 to 5000 | |
var sum = 0; | |
for(var i=1; i<=5000; i=i+2){ | |
sum += i; | |
} | |
console.log(sum); |
This file contains 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
//iSum(1) = 1 => 1 | |
// iSum(2) = 1 + 2 => 3 | |
// iSum(3) = 1 + 2 + 3 => 6 | |
// iSum(4) = 1 + 2 + 3 + 4 => 10 | |
// iSum(5) = 1 + 2 + 3 + 4 + 5 => 15 | |
var iSum = function(num){ | |
var sum = 0; | |
if(num > 0 ){ | |
for(var i=1; i<=num; i++){ |
This file contains 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
//factorial(3) = 3*2*1 | |
var factorial = function(num){ | |
var factor =1; | |
if(num > 0){ | |
for(var i=1; i<=num; i++){ | |
factor *= i; | |
} | |
return factor; | |
} | |
}; |
This file contains 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
// iFibonacci(0) = 0 => 0 | |
// iFibonacci(1) = 1 => 1 | |
// iFibonacci(2) = 1 => 1 | |
// iFibonacci(3) = 1 + 1 => 2 | |
// iFibonacci(4) = 1 + 2 => 3 | |
// iFibonacci(5) = 2 + 3 => 5 | |
// iFibonacci(6) = 3 + 5 => 8 | |
var iFibonacci = function(num){ | |
var num1 = 0; |
This file contains 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 rFibonacci = function(num){ | |
if(num === 1 || num ===2 ){ | |
return 1; | |
}else { | |
return rFibonacci(num-1) + rFibonacci(num-2); | |
} | |
}; | |
rFibonacci(6); |
This file contains 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 arr = [-90,-19,0,2,12,29,33,190,320]; | |
// rBS(arr, 5) => false | |
// rBS(arr, 12) => 4 | |
// rBS(arr, 0) => 2 | |
// rBS(arr, 190) => 7 | |
var rBs = function(arr,num){ | |
var max, min; | |
if(num > arr[Math.floor(arr/2)] ){ | |
max = arr.length-1; |
This file contains 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 iBs = function(arr, num){ | |
var max = arr.length-1, min = 0; midpt = Math.floor(arr.length/2); | |
for(var i=0; i<arr.length-1; i++){ | |
if(arr[midpt]> num){ | |
max = midpt; | |
midpt --; | |
} | |
else if(arr[midpt]<num){ | |
min = midpt; | |
midpt ++; |
OlderNewer