Skip to content

Instantly share code, notes, and snippets.

View globalroo's full-sized avatar

Andy globalroo

View GitHub Profile
const original = ["dog", "bee", "bee", ["John", "bob", "Doe", ["frank", "bob"]]].flat(Infinity)
original.forEach((item, index, array) => {
console.log("ITEM:", item, index, array)
})
const toUpperCaseMapper = original.map((item, index) => {
console.log("ITEM:", item, index)
return item.toUpperCase()
})
console.log(toUpperCaseMapper)
@globalroo
globalroo / TodoFastStateSwitcher.js
Last active May 22, 2024 09:20
Graham's three state switcher
import { useState } from "react"
import Iconify from "minimals-template/components/Iconify"
import { BlockClicks } from "lib/@components/block-clicks"
import { IconButton } from "@mui/material"
import { errorSnackbar } from "lib/snackbar/error-snackbar"
import { successSnackbar } from "lib/snackbar/success-snackbar"
export const TODO_STATE = {
TODO: "TODO",
DOING: "DOING",
var scores = [95, 85, 76, 65, 84, 91]
var total = 0
for(var i = 0; i < scores.length; i++) {
total += scores[i]
}
var average = total / scores.length
function displayAverage() {
document.getElementById('average').innerText = "Average Score: " + average
// Example 1:
const name = "Dave";
const greeting = `Hello, ${name}!`;
console.log(greeting); // What is logged?
// Example 2:
function example(name = "Guest") {
console.log(`Hello, ${name}!`);
}
example("Andy"); // What is logged?
@globalroo
globalroo / gist:158b77e24eae1ec17f116466d32c9599
Last active March 26, 2024 19:23
Junior developer JS questions
// Example 1:
console.log(x);
var x = 5;
// What is logged?
// Example 2:
const name = "John";
const greeting = `Hello, ${name}!`;
console.log(greeting);
// What is logged?
@globalroo
globalroo / useWindowSize.js
Created August 21, 2023 10:35
Can you see a problem here?
import { useState, useEffect } from "react";
function useWindowSize() {
const [windowSize, setWindowSize] = useState({
width: window.innerWidth,
height: window.innerHeight
});
useEffect(() => {
function handleResize() {
@globalroo
globalroo / gist:29949918b1034fdc1af4158bce5aeecd
Created October 9, 2022 20:04
Example pull request - please review
var MyString = ""
function gen(x, y) {
MyString = MyString + "<div>The test is returning: "
if (x == y) {
MyString = MyString + "true </div>"
} else MyString = MyString + "false </div>"
}
function myGenComponent() {
@globalroo
globalroo / code-review.js
Last active September 23, 2020 10:50
React code review, highlight this issues - say what you see as you see it.
var MyString = ""
function gen(x, y) {
MyString = MyString + "<div>The test is returning: "
if (x == y) {
MyString = MyString + "true </div>"
} else MyString = MyString + "false </div>"
}
function myGenComponent() {
@globalroo
globalroo / javascript-examples.js
Last active March 18, 2025 12:28
What's happening in these examples?
// Example 1
const myArray = ["John", "Doe"];
const array = [a, b, ...myArray];
// Example 2
const [a, b] = ["Andy", "James"];
console.log(b);
// Example 3
const value = (sfg20?.schedules?.plans ?? []);
@globalroo
globalroo / example-component2.jsx
Last active April 12, 2024 10:38
What's going on here? Can you see any problems?
// Can you spot a potential issue here? If so, what steps might you take to mitigate it?
function MyComponent() {
React.useEffect(() => {
function handleResize () {
console.log("Resize handler triggered!")
}
window.addEventListener("resize", handleResize)
})
// ...rest of Component