
Senior Software Engineer / Technical Lead @disneyplus
- Tweets4.5K
- Following1.1K
- Followers515
- Likes12.1K

ALT // Load the image const img = new Image(); img.src = url; await img.decode(); // Create a canvas the same size as the image const canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; // Draw the image to the canvas and get the bitmap bytes const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0); const bytes = ctx.getImageData(0, 0, canvas.width, canvas.height).data; // Convert to an array where each item is a full pixel (4 bytes) const pixels = new Uint32Array(bytes.buffer); // Get the number of unique values const palette = new Set(pixels); console.log(palette.size);
![This feature is about identifying capture groups via names. // Without named capture groups const re = /(\d{4})-(\d{2})-(\d{2})/; const match = re.exec('2021-03-04'); console.log(match[1]); // → 2021 (year) console.log(match[2]); // → 03 (month) console.log(match[3]); // → 04 (day) // With named capture groups 🔥 const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/; const match = re.exec('2021-03-04'); console.log(match.groups.year); // → 2021 console.log(match.groups.month); // → 03 console.log(match.groups.day); // → 04 // ... and with destructuring assignment 🔥🔥🔥 const [match, year, month, day] = re.exec('2021-03-04');](https://pbs.twimg.com/media/EzwqDp7VgAAQQnZ.jpg?name=small&format=webp)
ALT This feature is about identifying capture groups via names. // Without named capture groups const re = /(\d{4})-(\d{2})-(\d{2})/; const match = re.exec('2021-03-04'); console.log(match[1]); // → 2021 (year) console.log(match[2]); // → 03 (month) console.log(match[3]); // → 04 (day) // With named capture groups 🔥 const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/; const match = re.exec('2021-03-04'); console.log(match.groups.year); // → 2021 console.log(match.groups.month); // → 03 console.log(match.groups.day); // → 04 // ... and with destructuring assignment 🔥🔥🔥 const [match, year, month, day] = re.exec('2021-03-04');




























