Skip to content

Instantly share code, notes, and snippets.

View SergeyLipko's full-sized avatar

SergeyLipko

  • Kharkiv, Ukraine
View GitHub Profile
@SergeyLipko
SergeyLipko / compose.js
Last active June 3, 2017 12:23
Function composition (also with ramda )
// custom
const compose = (...functions) => data =>
functions.reduceRight((value, func) => func(value), data)
const pipe = (...functions) => data =>
functions.reduce((value, func) => func(value), data)
// with ramda
import r from 'ramda';
@SergeyLipko
SergeyLipko / RN_flatList_example.js
Created May 29, 2017 18:21
Example of using RN FlatList component with pagination and pull-refreshing
import React from 'react';
import {
View,
Text,
FlatList,
StyleSheet
} from 'react-native';
import { ListItem } from 'react-native-elements';
class Users extends React.Component {
import React from 'react';
const names = [{name: 'Arsen'}, {name: 'Vazgen'}, {name: 'Vlad'}];
const User = ({ name, ...rest }) => {
return (
<div>
<span>
{ name }
</span>
const delay = ms => new Promise(res => setTimeount(res, ms));
async function * gen() {
await delay(1000);
yield 1;
await delay(1000);
yield 2;
await delay(1000);
yield 3;
}
// ля получения значений подобно циклу for...of, можно использовать метод
let arr = [ 3, 5, 7 ];
arr.foo = "hello";
arr.forEach(function (element, index) {
console.log(element); // выведет "3", "5", "7"
console.log(index); // выведет "0", "1", "2"
});
/*
To learn this, you first have to learn what this is not, despite any assumptions or misconceptions that
may lead you down those paths. this is neither a reference to the function itself, nor is it a reference
to the function's lexical scope.
this is actually a binding that is made when a function is invoked, and what it references is determined
entirely by the call-site where the function is called.
*/
const reslut = someFunc(); // запись результат выполнения someFunc в переменную result
const funcLink = somfFunc; // запись ссылки на функцию в переменную funcLink
// * * * * * Default example * * * * *
this.age = 20;
const module = {
age: 12,
showAge: function() {
@SergeyLipko
SergeyLipko / tasks.js
Last active March 2, 2023 17:27
Задачки
// TODO - подумать, каким образом выполнить все это в функциональном стиле
// * * * * * Заполнение массива * * * * *
// Заполнить массив нулями и единицами, при этом данные значения
// чередуются, начиная с нуля.
function foo2() {
const len = 10;
let arr = [];
@SergeyLipko
SergeyLipko / map_forEach_difference.js
Created April 19, 2017 10:54
How Array.prototype.map() and Array.prototype.forEach() works
const myArr = [1, 2, 3, 4, 5, 6];
// map создает новый массив на основании вызова callback для каждого элемента (трансформация)
const newMap = myArr.map(i => {
return i * 2;
});
// forEach выполняет callback для каждого элемента массива (перебор)
const newForEach = myArr.forEach(i => {
return i * 2;
@SergeyLipko
SergeyLipko / custom_map.js
Last active May 3, 2017 18:23
Handmade Array.prototype.map()
function customMap(arr, callback, thisArgs) {
let newArr = [];
for (let i = 0; i < arr.length; i++) {
newArr.push(callback.call(thisArgs, arr[i]));
}
return newArr;
}