Skip to content

Instantly share code, notes, and snippets.

// https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json
var list = JSON.parse(document.querySelector("pre").textContent);
var allWords = Object.keys(list);
var allowed = allWords.filter(({ length }) => length > 3);
function increaseLetterCount(letters, letter) {
if (!letters[letter]) {
letters[letter] = 0;
}
// isNonNullObject()
console.log('Testing isNonNullObject() ...');
console.assert(isNonNullObject({}), "An Object should be a non-null object");
console.assert(isNonNullObject([]), "An Array should be a non-null object");
console.assert(isNonNullObject(new WeakMap()), "A WeakMap should be a non-null object");
console.assert(!isNonNullObject(null), "null should not be a non-null object");
console.assert(!isNonNullObject(''), "A String should not be a non-null object");
console.log('... complete!');
// isIterable()
console.log('Testing isIterable() ...');
@netcall-jlo
netcall-jlo / responsive.html
Created January 30, 2024 09:45
A quick demonstration of responsive JavaScript - based on a video whose URL I no longer remember
<!doctype html>
<html lang="en-GB">
<head>
<title>Testing reactivity</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,width=device-width">
</head>
@netcall-jlo
netcall-jlo / getScrollingParent.js
Created August 8, 2023 07:50
A function that takes an element and finds the parent element that scrolls. Useful in very specific circumstances
/**
* Takes an element and finds the parent element that would scroll.
*
* @param {Element} element
* Element whose scrolling parent should be returned.
* @return {Element|null}
* Parent element that scrolls. If no parent can be found, null is
* returned.
*/
function getScrollingParent(element) {
@netcall-jlo
netcall-jlo / findInObject.js
Created August 8, 2023 07:48
Allows an object to be searched to try and find a specific key or value. Useful for debugging
/**
* Finds any matches within the given object that satisfy the given search
* function.
*
* @param {Object} object
* Object to search.
* @param {Function} search
* Function that will identify a match. The function is passed the
* key, the value, and the full path. If it returns any truthy value
* then the result will be considered a match.