Created
December 18, 2019 12:20
-
-
Save kevinchisholm/ec07b22850e25a2ace288304d9123054 to your computer and use it in GitHub Desktop.
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 # 5: Demonstrating how the array validation now works better, regardless of the argument passed-in | |
function processRecords (records) { | |
if (!(records instanceof Array)) { | |
console.log(`Array provided array not valid`); | |
return; | |
} | |
if (!records.length) { | |
console.log(`No records to process`); | |
return; | |
} | |
records.forEach(record => { | |
console.log(`The record is: ${record}`); | |
}); | |
} | |
processRecords({length: 3}); | |
// Array provided array not valid | |
processRecords(true); | |
// Array provided array not valid | |
processRecords('hello'); | |
// Array provided array not valid | |
processRecords(12345); | |
// Array provided array not valid | |
processRecords(undefined); | |
// Array provided array not valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment