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`); |
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 # 6: Leverage Lodash to validate the array | |
function getScript(source, callback) { | |
var el = document.createElement('script'); | |
el.onload = callback; | |
el.src = source; | |
document.body.appendChild(el); | |
} |
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 # 7: Leverage the native isArray method to validate the array | |
function processRecords (records) { | |
if (!Array.isArray(records)) { | |
console.log(`Array provided array not valid`); | |
return; | |
} | |
if (!records.length) { | |
console.log(`No records to process`); |
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
$.getScript('https://bit.ly/get-script-example') | |
.done(() => { | |
console.log('The script load is done.'); | |
console.dir(myData); | |
}); | |
// Hello, I am a remote script that successfully loaded. | |
// The script load is done. | |
// ["foo", "bar", "baz"] |
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 getScript(scriptUrl, callback) { | |
const script = document.createElement('script'); | |
script.src = scriptUrl; | |
script.onload = callback; | |
document.body.appendChild(script); | |
} | |
function onScriptLoad() { | |
console.log('The script load is done.'); |
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 getScript(scriptUrl, callback) { | |
const script = document.createElement('script'); | |
script.src = scriptUrl; | |
script.onload = callback; | |
document.body.appendChild(script); | |
} | |
// anonymous function as 2nd argument | |
getScript('https://bit.ly/get-script-example', function () { |
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
console.dir(myData) // myData is not defined |
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 getLodash(t){var d=document.createElement('script');d.onload=t,d.src='http://bit.ly/lodash-4-17-15-min',document.body.appendChild(d)} | |
getLodash(() => { | |
// put your code here.... | |
}); |
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
const cars = [ | |
{ name: 'Mustang', maker: 'Ford', isSuv: false }, | |
{ name: 'EcoSport', maker: 'Ford', isSuv: true }, | |
{ name: 'CR-V', maker: 'Honda', isSuv: true } | |
]; | |
const match = _.find(cars, car => { return car.isSuv; }); | |
console.log(match); // {name: "EcoSport", maker: "Ford", isSuv: 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
const cars = [ | |
{ name: 'Mustang', maker: 'Ford', isSuv: false }, | |
{ name: 'EcoSport', maker: 'Ford', isSuv: true }, | |
{ name: 'CR-V', maker: 'Honda', isSuv: true } | |
]; | |
const match = _.find(cars, car => { return car.name === 'Mustang'; }); | |
console.log(match); // {name: "Mustang", maker: "Ford", isSuv: false} |