adonis install adonis-acl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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), []); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static getUniqueArrayListBy(arr, key) { | |
return [...new Map(arr.map((item) => [item[key], item])).values()]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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, |
OlderNewer