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
function upperCaseFirst(inputStr) { | |
var valueOfFirstChar = inputStr.charCodeAt(0); | |
console.log('Value of first character:', valueOfFirstChar); | |
var upperCaseLetter = String.fromCharCode(valueOfFirstChar - 32); | |
console.log('Uppercase first character:', upperCaseLetter); | |
var restOfString = inputStr.slice(1); | |
console.log('Rest of the string:', restOfString); |
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
export class Queue<T> { | |
private queue: T[]; | |
private length: number; // number of elements currently in the queue | |
private readonly maxSize: number; // maximum number of elements queue can contain | |
public constructor(maxSize: number) { | |
// Make sure maxSize is at least 1 | |
this.maxSize = maxSize > 0 ? maxSize : 10; | |
this.length = 0; | |
this.queue = new Array<T>(this.maxSize); |
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
package main | |
func main() { | |
} |
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
React.useEffect(() => { | |
let mouseDown: boolean = false; | |
... | |
return function cleanup() { | |
if (canvasRef.current) { | |
canvasRef.current.removeEventListener('mousedown', handleMouseDown); | |
canvasRef.current.removeEventListener('mouseup', handleMouseUp); | |
canvasRef.current.removeEventListener('mousemove', handleMouseMove); | |
} |
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
function handleMouseDown(evt: MouseEvent) { | |
mouseDown = true; | |
start = { | |
x: evt.clientX - canvasOffsetLeft, | |
y: evt.clientY - canvasOffsetTop, | |
}; | |
end = { | |
x: evt.clientX - canvasOffsetLeft, |
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
React.useEffect(() => { | |
let mouseDown: boolean = false; | |
let start: Coordinates = { x: 0, y: 0 }; | |
let end: Coordinates = { x: 0, y: 0 }; | |
let canvasOffsetLeft: number = 0; | |
let canvasOffsetTop: number = 0; | |
function handleMouseDown(evt: MouseEvent) { | |
mouseDown = 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
import * as React from 'react'; | |
type Coordinates = { | |
x: number; | |
y: number; | |
}; | |
function App() { | |
const canvasRef = React.useRef<HTMLCanvasElement>(null); | |
const [context, setContext] = React.useState<CanvasRenderingContext2D | null>(null); |
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
function handleMouseMove(evt: MouseEvent) { | |
if (mouseDown && context) { | |
start = { | |
x: end.x, | |
y: end.y, | |
}; | |
end = { | |
x: evt.clientX - canvasOffsetLeft, | |
y: evt.clientY - canvasOffsetTop, |
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 * as React from 'react'; | |
type Coordinates = { | |
x: number; | |
y: number; | |
}; | |
function App() {...} |
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
React.useEffect(() => { | |
if (canvasRef.current) { | |
const renderCtx = canvasRef.current.getContext('2d'); | |
if (renderCtx) { | |
setContext(renderCtx); | |
} | |
} | |
// Draw a rectangle |
NewerOlder