Skip to content

Instantly share code, notes, and snippets.

@SandyWyper
SandyWyper / Sorting.js
Last active January 6, 2019 11:40
Having issues with something I'm working on. This sinippet comes from the very end of my solution to this CodeWars problem ..... https://www.codewars.com/kata/strings-mix/train/javascript.
// In this challenge you are given two stings. You must take the letters from both strings and list them in a spacific order.
// I've extracted the letters, counted instances and filtered out ones not required. I am left with an array such as this.
// Each element of the array contains three values.
// [ 1, 2, 3 ]:
// 1. The number of the string that had the most of that letter. If both strings had the same number then an '=' is used.
// 2. The letter.
// 3. The number of instances that letter occured.
const arrayToSort = [ [ '2', 'b', 4 ],
[ '=', 'd', 2 ],
[ '2', 'f', 2 ],
@SandyWyper
SandyWyper / eventDelegation.js
Last active April 18, 2019 10:02
Event Delegation of dynamically added content.
function insertContent(results) {
let content = document.getElementById('inserted-content');
results.forEach(function(res) {
content.innerHTML += `
<div class="total-insert">
<div class="header-content">
<h1>This is the title</h1>
<div class="more-info"> //perhaps append data-thing-id="${res.id}"
@SandyWyper
SandyWyper / index.js
Last active March 27, 2021 20:25
Component had better do what it's told!
import React, { useState, useEffect } from "react"
import { get } from "lodash"
import useCallbackOnStateChange from "../lib/useCallbackOnStateChange"
const SomeComponent = ({ locationData }) => {
const [isGrid, setIsGrid] = useState(() =>
get(locationData, "state.isGrid", false)
)
const [counter, setCounter] = useState(0)