Skip to content

Instantly share code, notes, and snippets.

View kevboutin's full-sized avatar

Kevin Boutin kevboutin

View GitHub Profile
@kevboutin
kevboutin / compareArrays.js
Created October 17, 2023 15:38
Compare Arrays
const areEqual = (arr1, arr2) =>
arr1.sort().join(',') === arr2.sort().join(',');
const arr1 = [1, 2, 3, 4];
const arr2 = [3, 4, 1, 2];
const arr3 = [1, 2, 3];
console.log(areEqual(arr1, arr2)); // true
console.log(areEqual(arr1, arr3)); // false
@kevboutin
kevboutin / reverseString.js
Created October 17, 2023 15:40
Reverse a string
/* The old way:
const reverseString = (str) => {
let reversed = '';
for (let i = str.length - 1; i >= 0; i--) {
const ch = str[i];
reversed += ch;
}
return reversed;
};
const reverse = reverseString('javascript');
@kevboutin
kevboutin / groupArray.js
Created October 17, 2023 15:43
Group an array by object property
const groupBy = (arr, groupFn) => {
const grouped = {};
for (const obj of arr) {
const groupName = groupFn(obj);
if (!grouped[groupName]) {
grouped[groupName] = [];
}
grouped[groupName].push(obj);
}
return grouped;
@kevboutin
kevboutin / emailUtility.js
Created April 8, 2024 16:57
SendGrid email utility
const sgMail = require('@sendgrid/mail');
sgMail.setTimeout(40000);
const TAG = 'emailUtility';
const DEFAULT_SENDER = 'donotreply@somedomain.com';
/**
* Send an email.
*
@kevboutin
kevboutin / smsUtility.js
Created April 8, 2024 17:02
SMS Utility using Twilio
const twilio = require('twilio');
const TAG = 'smsUtility';
/**
* Send an SMS text message.
*
* Example response from Twilio:
* {
* "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",