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
/* | |
Iterators | Iterables: | |
Iterable (data structure): Iterator (obj that enumirates data): | |
[Symbol.iterator]() ---> .next() | |
`for of` interate only on Iterables | |
*/ | |
// array |
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 function step_logger(str, n) that print a string line by line from 0 to n with current index letters count. | |
Example: | |
step_logger("Hello world", 10); | |
H | |
He | |
Hel |
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 getClass(value) { | |
var str = Object.prototype.toString.call(value); | |
return /^\[object (.*)\]$/.exec(str)[1]; | |
} | |
console.log(getClass(null)); | |
console.log(getClass({})); | |
console.log(getClass([])); |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>IFRAME</title> | |
<script src="https://gist.githubusercontent.com/isRuslan/689f8d128e2f6934f9c8/raw/a1850688a6bafa8f800a805d83f055977435b5c9/index.js"></script> | |
</head> | |
<body> | |
Hello from iframe! | |
</body> |
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 *try_to_upper(items) { | |
// no effects! just iterate over `items`. | |
yield * items[Symbol.iterator](function * (item) { | |
try { | |
yield item.toUpperCase() | |
} catch (e) { | |
yield 'null' | |
} | |
}); | |
} |
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 x = 3e2; // 300 | |
var y = 3e-2; // 0.03 | |
// only NaN dosen't equal to itself | |
function isNaN (number) { | |
return number !== number; | |
} | |
// string -> number |
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 random = Math.floor(Math.random() * 100 + 1) | |
// your code | |
var guess = ... | |
console.assert(guess, random, 'NO!'): |
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): loop in loop | |
function unique_one (array) { | |
var result = []; | |
for (var i = 0; i < array.length; i++) { | |
for (var j = i; j < array.length; j++) { | |
if (array[i] == array[j]) { | |
// mmmm | |
} | |
} |
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 function that takes an integer flight_length (in minutes) and an array of integers movie_lengths (in minutes) and returns a boolean indicating whether there are two numbers in movie_lengths whose sum equals flight_length. | |
When building your function: | |
Assume your users will watch exactly two movies | |
Don't make your users watch the same movie twice | |
Optimize for runtime over memory | |
*/ |