Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
import './App.css';
class App extends React.Component {
state = {anonymousFunctions: true, count: 100};
updateCount = e => {
this.setState({count: e.target.value});
};
updateAnonymous = () => {
this.setState({anonymousFunctions: !this.state.anonymousFunctions});
let lastFocused = [];
setInterval(() => {
const focused = document.querySelector(':focus');
if (focused && lastFocused[lastFocused.length - 1] != focused) {
lastFocused.push(focused);
}
}, 100)
function handleAsManyLicenseCases(data, licenseID) {
const returnableLicense = {
allLicenses: [],
licenseStatement: licenseID,
spdx: {
osi: false,
fsf: false,
fsfAndOsi: false,
deprecated: false,
},
function filter(list, predicate) {
return list.reduce((acc, item) => {
if (predicate(item)) {
acc.push(item);
}
return acc;
}, []);
}
function map(list, func) {
return list.reduce((acc, item) => {
acc.push(func(item));
return acc;
}, []);
}
[
"Harry Potter",
"Gryffindor",
40,
"Hermione Granger",
"Gryffindor",
140,
"Draco Malfoy",
"Slytherin",
-20,
function flatMap(list, func) {
return list.reduce((acc, item) => {
const mappedItem = func(item);
if (Array.isArray(mappedItem)) {
acc = acc.concat(mappedItem);
} else {
acc.push(mappedItem);
}
return acc;
}, []);
[
{ name: "Harry Potter", house: "Gryffindor", points: 40 },
{ name: "Hermione Granger", house: "Gryffindor", points: 140 },
{ name: "Draco Malfoy", house: "Slytherin", points: -20 },
{ name: "Lin Manuel Miranda", house: "Slytherin", points: 5000 },
{ name: "Taylor Swift", house: "Slytherin", points: 100 },
{ name: "Cedric Diggory", house: "Hufflepuff", points: 12 },
{ name: "Sally Perks", house: "Hufflepuff", points: 15 },
{ name: "Luna Lovegood", house: "Ravenclaw", points: 100 },
{ name: "Cho Chang", house: "Ravenclaw", points: 100 }
function flatten(list) {
return list.reduce((acc, item) => {
if (Array.isArray(item)) {
acc = acc.concat(item);
} else {
acc.push(item);
}
return acc;
}, []);
}
[
[
{ name: "Harry Potter", house: "Gryffindor", points: 40 },
{ name: "Hermione Granger", house: "Gryffindor", points: 140 },
{ name: "Draco Malfoy", house: "Slytherin", points: -20 }
],
[
{ name: "Lin Manuel Miranda", house: "Slytherin", points: 5000 },
{ name: "Taylor Swift", house: "Slytherin", points: 100 },
{ name: "Cedric Diggory", house: "Hufflepuff", points: 12 }