View prototypal.js
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
function ParentScope(){ | |
this.aString = "parent string"; | |
this.aNumber = 100; | |
this.anArray = [10,20,30]; | |
this.anObject = {'property1': 'parent prop1', 'property2': 'parent prop2' }; | |
this.aFunction = function(){ console.log('parent output'); } | |
} | |
function ChildScope(){ | |
} |
View guess.py
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
from random import randrange | |
class Guess: | |
def play(self): | |
print "The computer will select a secret number between 1 and 10." | |
print "Try to find the secret number using a minimum number of guesses." | |
play, secret, guess, guesses, answer = True, 0, 0, 0, None | |
while play: |
View get_http.js
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
const get = (url) => { | |
return new Promise((resolve, reject) => { | |
const xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = () => { | |
if (xhr.readyState === XMLHttpRequest.DONE) { | |
if (xhr.status === 200) { | |
resolve(JSON.parse(xhr.responseText)); | |
} else { | |
reject(xhr); |
View callback.js
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
Array.prototype.click = function(fn, thisArg) { | |
const _self = thisArg || this; | |
for (let i = 0; i < _self.length; i++) { | |
fn.apply(thisArg, [_self[i], i, thisArg]); | |
// Mutation. | |
thisArg.values[i] = i; | |
} | |
}; |
View staircase.js
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
// Time Complexity O(n2) | |
const staircase = (n, c) => { | |
let y = []; | |
let s; | |
for (let i = 1; i <= n; i++) y[i - 1] = i; | |
for (let j = 1; j <= n; j++) { | |
s = y.length - j; | |
console.log(' '.repeat(s), c.repeat(j)); |
View cache.js
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
let cache = {} | |
const complex_computation = (a, b, timeout=5000, callback) => { | |
setTimeout(() => { | |
callback(null, a + b) | |
}, timeout) | |
} | |
const cached_computation = (a, b, callback) => { | |
const key = a + ':' + b |
View caesarCipher.js
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
/** | |
* Returns the result of having each alphabetic letter of the given text string shifted forward | |
* by the given amount, with wraparound. Case is preserved, and non-letters are unchanged. | |
* | |
* i.e. | |
* | |
* - caesarShift({ text: "abz", shift: 0 }) = "abz". | |
* - caesarShift({ text: "abz", shift: 1 }) = "bca". | |
* - caesarShift({ text: "abz", shift: 25 }) = "zay". | |
* - caesarShift({ text: "THe 123 !@#$", shift: 13 }) = "GUr 123 !@#$". |
View service worker.js
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 cacheName = 'weatherPWA-step-6-1'; | |
var dataCacheName = 'weatherData-v1'; | |
var filesToCache = [ | |
'/', | |
'/index.html', | |
'/scripts/app.js', | |
'/styles/inline.css', | |
'/images/clear.png', | |
'/images/cloudy-scattered-showers.png', | |
'/images/cloudy.png', |
View bubbleSort.js
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
// O (N^2) | |
var theArray = Array.prototype.slice.call(process.argv[2]); | |
var startTime | |
var endTime | |
console.log(theArray, 'unSorted') | |
function swapValues(one, two) { | |
var temp = theArray[one] | |
theArray[one] = theArray[two] |
View wordColor.js
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 colors = ["black", "blue", "brown", "green"]; | |
var doc = document.getElementById("content"); | |
var text = doc.innerHTML.split(" "); | |
function changeColor() { | |
doc.innerHTML = ""; | |
text.forEach(function(word, i) { | |
if (i != text.length) { | |
word += "\n"; |
OlderNewer