Skip to content

Instantly share code, notes, and snippets.

View AntonisFK's full-sized avatar
💭
Pushin 🅿️

Antonis AntonisFK

💭
Pushin 🅿️
  • Infuse
  • San Francisco
View GitHub Profile
@AntonisFK
AntonisFK / csv-to-json.js
Created March 13, 2016 01:31 — forked from iwek/csv-to-json.js
CSV to JSON Conversion in JavaScript
//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++){
@AntonisFK
AntonisFK / Print255.js
Created April 6, 2016 05:42
Write a program that would print all the numbers from 1 to 255
//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);
}
}
@AntonisFK
AntonisFK / oddNumbers.js
Created April 6, 2016 05:53
Write a program that would print all the odd numbers from 1 to 1000
//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);
}
@AntonisFK
AntonisFK / oddSum.js
Created April 6, 2016 05:58
Write a program that would print the sum of all the odd numbers from 1 to 5000
//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);
@AntonisFK
AntonisFK / isum.js
Created April 6, 2016 22:10
Implement a function iSum that behaves just like rSum but instead of using recursion to implement the solution it uses iteration.
//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++){
//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;
}
};
@AntonisFK
AntonisFK / iFibonacci.js
Last active April 6, 2016 23:05
Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. iFibonacci(6) => 8
// 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;
@AntonisFK
AntonisFK / rFibonacci.js
Created April 6, 2016 23:49
recursive Fibonacci sequence
var rFibonacci = function(num){
if(num === 1 || num ===2 ){
return 1;
}else {
return rFibonacci(num-1) + rFibonacci(num-2);
}
};
rFibonacci(6);
@AntonisFK
AntonisFK / rBs.js
Created April 7, 2016 00:31
Binary Search of an array.
// 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;
@AntonisFK
AntonisFK / iBs.js
Created April 7, 2016 00:53
iBS takes in an array and a value to search for. If the value is found in the array then iBS will return the index where the found value is. If the value is not found in the array then iBS returns false. Uses max min and mid
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 ++;