This file contains hidden or 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
// Example 1 - Using a for loop | |
var i = 0, | |
records = ['foo', 'bar', 'baz'], | |
arrayLength = records.length; | |
for (; i < arrayLength; i++) { | |
console.log(`(${i}) The record is: ${records[i]}`); | |
} |
This file contains hidden or 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
// example # 1: check if the length property of the passed-in array is 0 | |
function processRecords (records) { | |
if (records.length === 0) { | |
console.log(`No records to process`); | |
return; | |
} | |
records.forEach(record => { | |
console.log(`The record is: ${record}`); |
This file contains hidden or 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
//--------- PART 1 ------------------- | |
const objectA = { | |
foo: ['a', 'b', 'c'] | |
}; | |
const objectB = Object.assign({}, objectA); | |
console.dir(objectB); // {"foo":["a","b","c"]} |
This file contains hidden or 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
function validatePhoneForE164(phoneNumber) { | |
const regEx = /^\+[1-9]\d{10,14}$/; | |
return regEx.test(phoneNumber); | |
}; | |
validatePhoneForE164('+12125551212'); // true | |
validatePhoneForE164('12125551212'); // false | |
validatePhoneForE164('2125551212'); // false | |
validatePhoneForE164('+1-212-555-1212'); // false |
This file contains hidden or 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
function validateEmailAddress(emailAddress) { | |
const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/; | |
return emailRegex.test(emailAddress); | |
}; | |
validateEmailAddress('[email protected]'); // true | |
validateEmailAddress('[email protected]'); // true |
This file contains hidden or 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
_.remove(this.rates, { | |
id: resp.rate.id | |
}); | |
_.remove(this.rates, rate => { | |
return rate === resp.rate.id; | |
}); |
This file contains hidden or 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
function sleep (milliseconds) { | |
return new Promise(resolve => setTimeout(resolve, milliseconds)); | |
}; | |
function goToSleep (milliseconds) { | |
console.log('Going to bed now...'); | |
await sleep (milliseconds); | |
console.log('Finished sleeping!'); |
This file contains hidden or 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
// example # 2: check if the length property of the passed-in array is "truthy" | |
function processRecords (records) { | |
if (!records.length) { | |
console.log(`No records to process`); | |
return; | |
} | |
records.forEach(record => { | |
console.log(`The record is: ${record}`); |
This file contains hidden or 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
// example # 3: If we pass-in an object with a lenght property, the code throws an error | |
function processRecords (records) { | |
if (!records.length) { | |
console.log(`No records to process`); | |
return; | |
} | |
records.forEach(record => { | |
console.log(`The record is: ${record}`); |
This file contains hidden or 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
// example # 4: Make sure that the passed-in object is an instance of the Array constructor | |
function processRecords (records) { | |
if (!(records instanceof Array)) { | |
console.log(`Array provided array not valid`); | |
return; | |
} | |
if (!records.length) { | |
console.log(`No records to process`); |