Skip to content

Instantly share code, notes, and snippets.

View MentalGear's full-sized avatar

MentalGear

View GitHub Profile
@MentalGear
MentalGear / mergeDedupeArrays.js
Created January 5, 2022 16:33
Combine and deduplicate Arrays
// Note: Does only work with primities (numbers, strings) as objects/arrays, etc are saved by reference
// meaning even if the object is the same twice, the reference will be different and Set() will not have unique true values
// this could maybe be fixed by JSON.stringifying non-primitive values on save
export function mergeDedupeArrays(arrays) {
let combinedArrays = []
for (let array of arrays) {
combinedArrays = combinedArrays.concat(array)
}
return [...new Set(combinedArrays)]
@MentalGear
MentalGear / regex_url_network_protocol.js
Last active July 25, 2021 09:10
Regex: Get URL Network Protocol
// based upon:
// https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-extract-a-protocol-and-port-number-from-a-url
const url = 'http://www.google.com/fwef://gerg';
const regex = /^(?<proto>\w+):/g;
const found = url.match(regex);
console.log(found);