This file contains 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
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 |
This file contains 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
/* 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'); |
This file contains 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
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; |
This file contains 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
const sgMail = require('@sendgrid/mail'); | |
sgMail.setTimeout(40000); | |
const TAG = 'emailUtility'; | |
const DEFAULT_SENDER = 'donotreply@somedomain.com'; | |
/** | |
* Send an email. | |
* |
This file contains 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
const twilio = require('twilio'); | |
const TAG = 'smsUtility'; | |
/** | |
* Send an SMS text message. | |
* | |
* Example response from Twilio: | |
* { | |
* "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", |
OlderNewer