Skip to content

Instantly share code, notes, and snippets.

View kevinchisholm's full-sized avatar

Kevin Chisholm kevinchisholm

View GitHub Profile
// 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`);
// 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);
}
// 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`);
@kevinchisholm
kevinchisholm / get-script-example-2.js
Last active December 19, 2019 12:29
jQuery.getScript Alternatives - Example 2
$.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"]
@kevinchisholm
kevinchisholm / get-script-example-3.js
Last active December 19, 2019 12:33
jQuery.getScript Alternatives - Example 3
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.');
@kevinchisholm
kevinchisholm / get-script-example-4.js
Last active June 23, 2021 22:03
jQuery.getScript Alternatives - Example 4
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 () {
@kevinchisholm
kevinchisholm / get-script-example-1.js
Created December 19, 2019 12:25
jQuery.getScript Alternatives - Example 1
console.dir(myData) // myData is not defined
@kevinchisholm
kevinchisholm / load-lodash.js
Last active December 20, 2019 11:17
Loading lodash.js in the console
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....
});
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}
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}