Skip to content

Instantly share code, notes, and snippets.

@batazo
batazo / RegExp match indices.js
Created July 3, 2022 18:45
RegExp match indices
const fruits ="Fruits:apples, oranges, pears";
const regex = /(apples)/gd;
const matches = [...fruits.matchAll(regex)];
console.log(matches[0]);
@batazo
batazo / Object.hasOwn.js
Created July 3, 2022 18:34
Object.hasOwn()
const person = Object.create(null);
person.age = 21;
if (Object.hasOwn(person, 'age')) {
console.log(person.age); // true - works regardless of how the object was created
}
if (person.hasOwnProperty('age')){ // throws error - person.hasOwnProperty is not a function
console.log('hasOwnProperty: ', person.age);
}
@batazo
batazo / AT-Method-example.js
Created July 3, 2022 18:27
AT METHOD FOR INDEX
const fruits = ['apples', 'oranges', 'pears'];
console.log(fruits[fruits.length - 1]); // pears
console.log(fruits.at(0)); // apples
console.log(fruits.at(-1)); // pears
@batazo
batazo / index.js
Created July 3, 2022 18:23
Ergonomic Brand check
class User {
username;
#address;
set #address(addr) {
#address = addr;
}
get #address() {
return #address;
@batazo
batazo / easy-tetris-v54-unpublished.markdown
Created June 22, 2022 16:39
EASY Tetris - v54-Unpublished
@batazo
batazo / easy-tetris-v52-unpublished.markdown
Created June 9, 2022 21:15
EASY Tetris - v52-Unpublished
@batazo
batazo / distances-between-multiple-gps-coordinates-to-json-array.markdown
Created May 30, 2022 22:00
Distances Between Multiple GPS coordinates to JSON/ARRAY
@batazo
batazo / distances-between-multiple-gps-coordinates-to-json-array.markdown
Last active May 30, 2022 21:55
Distances Between Multiple GPS coordinates to JSON/ARRAY