This file contains 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
import React, { useState, useEffect, useReducer, useContext, useRef, createContext } from "react"; | |
// Hook definition. | |
export const useContextAndReducer = (reducer, context) => { | |
const ctx = useContext(context); | |
const [state, dispatch] = useReducer(reducer, ctx.state); | |
const { setState } = ctx; | |
// Update the context when the state changes from the reducer. | |
useEffect(() => { |
This file contains 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
/** | |
* This is just an example of how concise the FizzBuzz solution can be. | |
* This may not be the most efficient or elegant solution in the world, but eh, it's a bit of fun! :) | |
*/ | |
// Just off load the logic to a method for the sake of ease. | |
// It could be a one line solution, but it's a little harder to read that way. | |
const print = i => (i % 3 == 0 ? 'Fizz' : '') + (i % 5 == 0 ? 'Buzz' : '') || i; | |
// Now to iterate over an array with 100 elments & print the solution. |
This file contains 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
import { Observable } from 'rxjs'; | |
export class BasicFileInformation { | |
public fileName: String; | |
public fileSize: Number; | |
public fileData: String | ArrayBuffer; | |
public fileMimeType: String; | |
constructor(fileName: String, fileSize: Number, fileData: String | ArrayBuffer, fileMimeType: String) { | |
this.fileName = fileName; |
This file contains 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
var css = Array.from(document.styleSheets).reduce((l, s) => { | |
l.push([...s.cssRules].map(c => c.cssText)); | |
return l; | |
}, []).map(arr => arr.join()).join(); | |
console.log(css); |
This file contains 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
// A functional example | |
return someList.stream() | |
.map(String::toLowerCase) | |
.anyMatch(x::contains); | |
// A more traditional example | |
for (String str : someList) { | |
if (x.contains(str.toLowerCase())){ | |
return true; | |
} |
This file contains 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
// Just a short hand function to assist the push function, it simply | |
// turns a string into an array, and due to surrogate pairs, | |
// this solution removes all instances of null, then it sorts the array, | |
// and finally returns it as a string. | |
const sort = s => [...s].filter(x => x != null).sort().join(''); | |
// A function that will assist the anagrams function, it will | |
// essentially state whether or not to push a string onto the | |
// anagrams array or to push null onto the array, there are times |