Skip to content

Instantly share code, notes, and snippets.

View farynaio's full-sized avatar
🎯
Focusing

Adam Faryna farynaio

🎯
Focusing
  • London, UK
View GitHub Profile
@farynaio
farynaio / wordpress-plugin-svn-to-git.md
Created June 11, 2019 08:18 — forked from kasparsd/wordpress-plugin-svn-to-git.md
Using Git with Subversion Mirroring for WordPress Plugin Development
@farynaio
farynaio / index.js
Created October 8, 2018 17:37
Node.js flatten()
const { expect } = require("chai")
function flatten(array) {
return array.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), [])
}
describe("#flatten", () => {
it("should return flattened array", () => {
const input = [[1, 2, [3]], 4]
expect(flatten(input)).to.deep.equal([1, 2, 3, 4])
@farynaio
farynaio / gist:0349b1c430b37115e34e3fc600a6178e
Last active October 8, 2018 17:56
Javascript Order Objects by Average Rank
function orderByRank(array) {
var arrayCopy = array.slice(); // if we don't want to modify org array
arrayCopy.sort(function(a, b) {
return a.ranking - b.ranking;
});
return arrayCopy;
}
@farynaio
farynaio / gist:ac52085387504d13ddabe43926fa3aee
Last active October 8, 2018 17:54
Javascript Objects by Rank
function objectsByRanking(data) {
return data.sort(function(a, b) { return a.ranking - b.ranking; })
}
function averageRanking(data) {
return data.reduce(
function(prev, curr) { return { ranking: prev.ranking + curr.ranking }; }, { ranking: 0 }
).ranking / data.length;
}
@farynaio
farynaio / gist:c01fc5027d7251e18177f8cfacd01026
Last active October 8, 2018 17:55
Javascript Object Discriminator filter
function discriminator(data) {
if (!data) {
return null;
}
return data.filter(function(item) {
return item.age >= 30 && item.age <= 40;
});
}