Skip to content

Instantly share code, notes, and snippets.

View edrdesigner's full-sized avatar

Eduardo Reichert edrdesigner

View GitHub Profile
// Javascript one-liner to calculate total minesweeper neighbours
// Polyfill for ECMA 2019
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
if (!Array.prototype.flat) {
Array.prototype.flat = function () {
return this.reduce((acc, val) => acc.concat(val), []);
}
}
@edrdesigner
edrdesigner / Adonis-ACL.md
Created March 10, 2022 21:37 — forked from maykbrito/Adonis-ACL.md
Basic step-by-step to use ACL in AdonisJS

Install

adonis install adonis-acl

Config

app.js

@edrdesigner
edrdesigner / binary-search.js
Created March 23, 2022 16:12
Binary search algorithm
const arr = ['a','b', 'c', 'd','x', 'y', 'z'];
function findMe(target, start, end) {
if (start > end) return 'not found';
const middle = Math.floor((start+end)/2);
if (arr[middle] === target) {
return `found it at index ${middle}`;
}
static getUniqueArrayListBy(arr, key) {
return [...new Map(arr.map((item) => [item[key], item])).values()];
}
/**
In a game, there is a string, direction, of length n that consists of characters
L and R.
L denotes left. R denotes right, and there is a line segment of
length 2" that extends from [0, 2"], a player takes n turns.
In the th turn,
• The player places the number i at the center of the current line segment.
• If direction[i] = L; the player proceeds in the left direction, eliminating the right half of the current line segment,
and vice versa for direction[i] = 'R'.
Following this rule, find the final order of numbers on the line segment,