Skip to content

Instantly share code, notes, and snippets.

View dolvik's full-sized avatar

Viktor Kireev dolvik

View GitHub Profile
@dolvik
dolvik / index.js
Created May 31, 2016 08:27
Properly nested string
/*
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 = {
@dolvik
dolvik / index.js
Created May 31, 2016 09:16
Triangle. Determine whether a triangle can be built from a given set of edges.
//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++){
@dolvik
dolvik / index.js
Created September 2, 2016 06:54
JS functional calc
var five = num(5);
var one = num(1);
console.log(five(plus(one()))); //6
function plus(arg){
return function(arg2){
return arg + arg2;
}
}
@dolvik
dolvik / index.js
Created September 2, 2016 07:24
Преобразование дерева в пункты меню по уровням вложенности
/*
Результат
[
['1', '2', '3'],
['1-1', '1-2', '3-1', '3-2', '3-3'],
['1-2-1', '3-2-1', '3-2-2']
]
*/
var input = [
# 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 ->
@dolvik
dolvik / index.js
Created April 12, 2017 11:59
Small util functions
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]), [] );
@dolvik
dolvik / index.js
Last active October 11, 2017 12:15
Log function that is used ing https://github.com/visionmedia/debug
//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);
}