Created
January 17, 2024 21:47
-
-
Save juliobitencourt/097782871df5225af8094485fc0c62ea to your computer and use it in GitHub Desktop.
JavaScript Snippets
This file contains hidden or 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
// Create an array | |
Array.from({ length: 100 }, (v, i) => i) | |
// Copy to clipboard | |
const copyToClipboard = (content) => navigator.clipboard.writeText(content) | |
copyToClipboard("Hello fatfish") | |
// Get mouse selection | |
const getSelectedText = () => window.getSelection().toString() | |
getSelectedText() | |
// Shuffle an Array | |
const shuffleArray = array => array.sort(() => Math.random() - 0.5) | |
shuffleArray([ 1, 2,3,4, -1, 0 ]) // [3, 1, 0, 2, 4, -1] | |
// Get the average of multiple numbers | |
const average = (...args) => args.reduce((a, b) => a + b, 0) / args.length | |
average(0, 1, 2, -1, 9, 10) // 3.5 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment