Maybe I was not clear enough so I will explain the issue again after posting the versions you asked about
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
/* VT100 terminal reset (<ESC>c) */ | |
console.log('\033c'); | |
/* numbers comparations */ | |
> '2' == 2 | |
true | |
> '2' === 2 |
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
// rawurlencode is more or less like encodeURIComponent | |
function urlencode (str) { | |
// php like urlencode for javascript | |
str = (str + '') | |
return encodeURIComponent(str) | |
.replace(/!/g, '%21') | |
.replace(/'/g, '%27') | |
.replace(/\(/g, '%28') | |
.replace(/\)/g, '%29') | |
.replace(/\*/g, '%2A') |
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
/* takes single number and convert it to a position | |
@arg: | |
Int: number | |
@returns: | |
String: position (ie: 1st , 2nd , 3rd , 4th ,... 101st , 1004th ...) | |
*/ | |
var calcPosition = (rank) => { | |
let final | |
let length = rank.toString().length | |
--length |
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
""" Tower of Hanoi """ | |
def printMove(fr , to): | |
print("move from {} to {} ".format(str(fr),str(to)) ) | |
def towers(num , original , dist ,spare): | |
if num == 1: | |
printMove(original , dist) | |
else: | |
towers(num-1, original , spare , dist) # move the upper stack to spare to | |
towers(1, original , dist , spare) # move the bigger to to |
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 $ = document.querySelector.bind(document); | |
const $$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function (name, fn) { | |
this.addEventListener(name, fn); | |
}; | |
NodeList.prototype.__proto__ = Array.prototype; // eslint-disable-line | |
NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) { |
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
import sys | |
from urllib.request import urlopen | |
def fetch_words(url): | |
words = [] | |
with urlopen(url) as f: | |
for line in f: | |
for word in line.decode('utf-8').split(): | |
words.append(word) | |
return words |
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 bubble_sort(arr){ | |
for(let i = 0 , n = arr.length ; i < n - 1 ; n -= 1){ | |
for(let ii = i , j = i + 1 ; j < n ; j += 1 , ii += 1){ | |
if(arr[ii] > arr[j]){ | |
let temp = arr[ii] | |
arr[ii] = arr[j] | |
arr[j] = temp | |
} | |
} | |
} |
##what are generators##
- They're pausable functions, pausable iterable functions, to be more precise
- They're defined with the *
- every time you
yield
a value, the function pauses until.next(modifiedYieldValue)
is called
var myGen = function*() {
var one = yield 1;
var two = yield 2;
var three = yield 3;
console.log(one, two, three);