Skip to content

Instantly share code, notes, and snippets.

View Beraliv's full-sized avatar
📺
Contributing to OSS 7-9am, 7-9pm UK time (respond within a week)

Alexey Berezin Beraliv

📺
Contributing to OSS 7-9am, 7-9pm UK time (respond within a week)
View GitHub Profile
@Beraliv
Beraliv / all-permutations.js
Created November 3, 2019 19:26
Find all permutations for a specified string
/**
* Traverse permutation to add new letter to every new position
*
* @example
* generateNextPermutation(['a','b'],'c')
* // => [['c','a','b'],['a','c','b'],['a','b','c']]
*/
function generateNextPermutation(permutation, ch) {
const destination = [];
for (let i = 0; i <= permutation.length; i++) {
import { filterT, map, mapT, pipeT, takeT, transduce, where } from 'nanoutils';
const isEven = value => value % 2 === 0;
const filterPredicates = {
name: ({ author }) => name => author === undefined || name === author,
timestamp: ({ from, to }) => timestamp =>
from === undefined ||
to === undefined ||
(from <= timestamp && timestamp <= to)
function debugT() {
return function(reducer) {
return function(acc, v) {
debugger;
return reducer(acc, v);
};
};
}
function consoleT() {
return function(reducer) {
return function(acc, v) {
console.log(acc, v);
return reducer(acc, v);
};
};
}
import { add, filterT, mapT, pipeT, transduce } from 'nanoutils';
const isEven = value => value % 2 === 0;
const transducers = array => {
const transducer = pipeT(
// transforms value to value + 1
mapT(add(1)),
// ignores odd values
filterT(isEven),
const isEven = value => value % 2 === 0;
const filterPredicates = {
// if available, checks if names equal
author: ({ name }, { author }) => author === undefined || name === author,
// if available, checks if date starts from a specified value
from: ({ timestamp }, { from }) => from === undefined || from <= timestamp,
// if available, checks if date ends with a specified value
to: ({ timestamp }, { to }) => to === undefined || timestamp <= to
};
const isEven = value => value % 2 === 0;
const isFilteredAuthor = ({ name }, { author }) => {
// if filter is not available, value is not filtered
if (author === undefined) {
return true;
}
// checks if names equal
return name === author;
};
const isEven = value => value % 2 === 0;
const coreJs = array => {
// starts from 0
let sum = 0;
// iterates over array
for (let i = 0; i < array.length; i++) {
// transforms value to value + 1
const result = array[i] + 1;
// ignores odd values
const isEven = value => value % 2 === 0;
const mapFilterReduce = array =>
// gets values from array
array
// transforms value to value + 1
.map(value => value + 1)
// ignores odd values
.filter(isEven)
// applies addition
@Beraliv
Beraliv / tutorial.md
Created August 16, 2018 07:57 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.