Skip to content

Instantly share code, notes, and snippets.

View 3assy2018's full-sized avatar

Mohamed El-Assy 3assy2018

View GitHub Profile
@3assy2018
3assy2018 / Pipeline.js
Created July 4, 2020 09:37
This code implements pipeline pattern using ES6. It is inspired by Laravel Framework pipeline pattern.
export default class Pipeline {
passable = null;
pipes = [];
method = 'handle';
send = (passable) => {
@3assy2018
3assy2018 / AccumulativeAverageChangePercentage.js
Last active July 5, 2020 12:36
This function calculates change percentage between 2 pairs of values and accumulates the average and the last iterated value as previous value in the next iteration.
calculateAccumulativeAverageChangePercentage(set, initial) {
let deltaObj = set.reduce((total, currentValue) => {
let currentChange = (currentValue - total.prevValue) / Math.abs(total.prevValue);
let averageMode = total.change != 0 ? 2 : 1;
return {
change: (currentChange + total.change) / (averageMode),
prevValue: currentValue
};
}, {change: 0, prevValue: initial});