Skip to content

Instantly share code, notes, and snippets.

/*
Welcome to the JavaScript Visual Interpreter!
It can help you understand exactly how
and why your code executes the way that it does.
Try typing a snippet of JavaScript here
stepping through each operation with the buttons above
--or to get started quickly,
try one of the code snippets in the list below.
You can check out the code at https://github.com/visualinterpreter
var applyResult = 0;
var callResult = 0;
var sum = function(a, b, c){
return a + b + c;
};
applyResult = sum.apply(null, [1,2,3]); // returns 6
callResult = sum.call(null, 1, 2, 3); //also returns 6
@kwyn
kwyn / Factorial
Last active August 29, 2015 13:58
var f = [];
var factorial = function (n) {
if (n === 0 || n === 1){
return 1;
}
if (f[n] > 0){
return f[n];
}
f[n] = factorial(n-1) * n;
return f[n];
@kwyn
kwyn / Fibonacci
Last active August 29, 2015 13:58
var fibonacci = function(n, output) {
var a = 1, b = 1, sum;
for (var i = 0; i < n; i++) {
output.push(a);
sum = a + b;
a = b;
b = sum;
}
};
var is_even = function(a){
if (a === 0){
return true;
}else{
return is_odd(a - 1, 'testb');
}
};
var is_odd = function(b){
if (b === 0){
var trampoline = function(fun){
var args = Array.prototype.slice.call(arguments,1);
var result = fun.apply(this, args);
while(typeof result === 'function') {
result = result();
}
return result;
};
var countDown = function(n){
var bubbleSort = function(array){
for(var i = 0; i < array.length-1 ; i++){
for(var j = 0; j < array.length-1 ; j++ ){
if(array[j]>array[j+1]){
var swap = array[j];
array[j] = array[j+1];
array[j+1] = swap;
}
}
}
/**
* A prime number is a whole number that has no other divisors other than
* itself and 1. Write a function that accepts a number and returns true if it's
* a prime number, false if it's not.
*/
var primeTester = function(n) {
if( n === 1) return false;
from HTMLParser import HTMLParser
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
def get_data(self):
return ''.join(self.fed)
var longestPalindrome = function (string) {
// Your code here
// Sliding window problem.
// If string is palindrom, return string
// else check if substring of length stringLength-n is palindrome.
// As soon as you get a palindrome you've found the longest palindrome
// since you're shrinking the window and you want the longest one.
var stringLength = string.length
var n = 0;
while( n < stringLength){