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
//https://github.com/visionmedia/debug | |
function log() { | |
// this hackery is required for IE8/9, where | |
// the `console.log` function doesn't have 'apply' | |
return 'object' === typeof console | |
&& console.log | |
&& Function.prototype.apply.call(console.log, console, arguments); | |
} |
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 delayed = (ms, fn, ctx) => (...args) => { | |
setTimeout(fn.bind(ctx, ...args), ms); | |
}; | |
const revert = (arr) => arr.reduce((acc, curr, i, arr) => acc.concat(arr[arr.length - i - 1]), [] ); |
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
# Your init script | |
# | |
# Atom will evaluate this file each time a new window is opened. It is run | |
# after packages are loaded/activated and after the previous editor state | |
# has been restored. | |
# | |
# An example hack to log to the console when each text editor is saved. | |
# | |
# atom.workspace.observeTextEditors (editor) -> | |
# editor.onDidSave -> |
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
/* | |
Результат | |
[ | |
['1', '2', '3'], | |
['1-1', '1-2', '3-1', '3-2', '3-3'], | |
['1-2-1', '3-2-1', '3-2-2'] | |
] | |
*/ | |
var input = [ |
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 five = num(5); | |
var one = num(1); | |
console.log(five(plus(one()))); //6 | |
function plus(arg){ | |
return function(arg2){ | |
return arg + arg2; | |
} | |
} |
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
//http://codility.com/demo/take-sample-test/triangle | |
function solution(arr) { | |
if (arr.length < 3){ | |
return 0; | |
} | |
arr.sort(function(a, b){return a - b;}); | |
for (var i = 0, len = arr.length; i < len - 2; i++){ |
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
/* | |
A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: | |
S is empty; | |
S has the form "(U)" or "[U]" or "{U}" where U is a properly nested string; | |
S has the form "VW" where V and W are properly nested strings. | |
For example, the string "{[()()]}" is properly nested but "([)()]" is not. | |
*/ | |
var rb = { |
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 getNewArray(arr){ | |
var res = arr.slice(); | |
var max = res.length - 1; | |
var i, e; | |
while(max > 0){ | |
i = getRandomIntInclusive(0, max); |
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 isPalindrome(s){ | |
s = s.toLowerCase().replace(/[^а-яё]/g, ""); | |
for (var i = 0; i < s.length / 2; i++){ | |
var b = s[i]; | |
var e = s[s.length - 1 - i]; | |
if (b !== e) | |
{ | |
return false; |
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
//Раньше наследование делали с помощью такой функции-помощника. | |
//Вся цель этой функции - присвоить свойству prototype дочернего класса новый объект, прототип которого будет ссылаться на свойство prototype объекта parent | |
function inherit(child, parent){ | |
//создается вспомагательная функция, т.е. объект типа Function | |
function F(){}; | |
//объект типа Function имеет свойство prototype, которое мы перезаписываем на parent.prototype | |
F.prototype = parent.prototype; | |
//создаем новый объект, прототипом которого будет F.prototype, который в свою очередь ссылается на parent.prototype | |
//т.е. new F() создает объект obj: | |
//obj.__proto__ = parent.prototype |
NewerOlder