Skip to content

Instantly share code, notes, and snippets.

View Array.nth.of.js
const
arrPrototype = Object.getPrototypeOf([]);
const {
from: arrayFrom,
isArray,
} = Array;
function createListOfChunkLists(arr, chunkCount) {
View Array.nthItem.js
const
arrPrototype = Object.getPrototypeOf([]);
const {
from: arrayFrom,
isArray,
} = Array;
function isFunction(type) {
View Array.forEach.stopIteration.js
const
arrPrototype = Object.getPrototypeOf([]);
const {
from: arrayFrom,
isArray,
} = Array;
function isFunction(type) {
View createRemoveScheme.js
/*
* see: [https://stackoverflow.com/questions/66303388/how-to-most-efficiently-splice-an-array-while-looping-through-a-list-of-indices/66304184#66304184]
*
* StackOverflow :: How to most efficiently splice an array
* while looping through a list of indices
* of to be removed array items?
*/
function createRemoveScheme(indexList, targetList) {
return Array
@petsel
petsel / localeCompare.defaultCompare.js
Created Feb 15, 2021
provides a `localeCompare` based compare function which can be used like `[/* ... */].sort(localeCompare)`
View localeCompare.defaultCompare.js
function defaultCompare(a, b) {
return ((a < b) && -1) || ((a > b) && 1) || 0;
}
// function localeCompare(a, b) {
// return a.localeCompare
// ? a.localeCompare(b)
// : defaultCompare(a, b);
// }
// - supports additional `…[, locales[, options]` argument binding
View Boolean.isTrue.isFalse.js
/**
* `Boolean.isTrue` / `Boolean.isFalse` is a fun implementation of Smalltalk's [https://en.wikipedia.org/wiki/Smalltalk]
* `ifTrue` / `ifFalse` control structures [https://en.wikipedia.org/wiki/Smalltalk#Control_structures].
*
* It is nothing one would really desire in JavaScript unless one is looking for an alternative to its native `if...else`
* statement and has deeply fallen in love with using function expressions all along.
*
* EN: [https://en.wikipedia.org/wiki/Smalltalk#Control_structures]
* DE: [https://de.wikipedia.org/wiki/Smalltalk_(Programmiersprache)#IF-Anweisung]
*/
View Function.compose.js
// see: "Compose in JavaScript, not applying functions correctly?" asked by Dan Mantyla - Nov 10, 2014
// answer: [https://stackoverflow.com/questions/26835095/compose-in-javascript-not-applying-functions-correctly/28880612#28880612]
(function (Function, Object) {
const fctPrototype = Function.prototype;
const FUNCTION_TYPE = (typeof Function);
function isFunction(type) {
return (
@petsel
petsel / Function.afterThrowing.js
Created Sep 2, 2020
implementation of a possible static `Function.afterThrowingAll` which does run a list of whatever functions failsafe
View Function.afterThrowing.js
// see [https://gist.github.com/petsel/9ddf5ce515f1344c84bd#file-function-afterthrowing-js]
(function (Function) {
const fctPrototype = Function.prototype;
const FUNCTION_TYPE = (typeof Function);
function isFunction(type) {
return (
(typeof type == FUNCTION_TYPE)
@petsel
petsel / Function.afterFinally.js
Created Sep 2, 2020
implementation of a possible static `Function.afterFinallyAll` which does run a list of whatever functions failsafe
View Function.afterFinally.js
// see [https://gist.github.com/petsel/3b31cd5e63d43b9e7c4e#file-function-afterfinally-js]
(function (Function) {
const fctPrototype = Function.prototype;
const FUNCTION_TYPE = (typeof Function);
function isFunction(type) {
return (
(typeof type == FUNCTION_TYPE)
View getAllAccessiblePropertyNames.js
function isBooleanValue(type) {
return (typeof type === 'boolean');
}
function isNumberValue(type) {
return (typeof type === 'number');
}
function isStringValue(type) {
return (typeof type === 'string');
}