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
// Changes to javascript functions are contained in .js files in the "$sync_path" folder | |
$updjs = []; // each element contains a set of synctactically correct javascript statements | |
$maxtime = $lastupd; // save the most recent update sent | |
// List all .js files updated later than $lastupd"); | |
foreach (scandir($sync_path) as $file) { | |
if (is_dir($file) || pathinfo($file,PATHINFO_EXTENSION)!='js') continue; | |
$filetime = date('Y-m-d H:i:s',filemtime("$sync_path/$file")); | |
if ($filetime>$lastupd) { | |
$updjs[] = file_get_contents("$sync_path/$file"); |
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 findCheapest(orders) { | |
var cheapest = 999999999; | |
for (i=0; i<orders.length; i++) { | |
cheapest = Math.min(cheapest, findCheapestItem(orders[i].items) ); | |
} | |
return cheapest; | |
} | |
function findCheapestItem(items) { | |
var cheapest = 999999999; |
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
glob = {}; // global object to keep the initial list of properties | |
glob.before = Object.keys(window); // save all window properties before any script is loaded | |
// showDiff shows (on console.log) the list of "new" properties | |
glob.showDiff = function(before,after) { | |
for (let p in after) { | |
if (before[p] === undefined) { | |
console.log(p,': ', after[p], ' = ', window[p]); | |
} |
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
glob = {}; // global object to keep the initial list of properties | |
glob.initial = Object.keys(window); // save all window properties before any script is loaded | |
// showDiff shows (on console.log) the list of "new" properties | |
glob.showDiff = function(before,after) { | |
after.forEach( function(prop) { | |
if (before.indexOf(prop)<0) { | |
console.log(prop,': ', window[prop]); | |
} |
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
glob.afterLoad = Object.keys(window); | |
glob.showDiff(glob.initial,glob.afterLoad); |
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
glob.showDiff(glob.afterLoad, Object.keys(window)); |
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
let car = { | |
make: 'Ferrari', | |
model: '812GTS', | |
price: 336000, | |
colour: 'rosso corsa', | |
options: {wheels: 'standard rims', seats: 'Daytona seats', interior: 'charcoals'} | |
}; |
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
let cars = [ | |
{id: 1, make: 'Ferrari', model: '812GTS', price: 336000, colour: 'rosso corsa'}, | |
{id: 2, make: 'Ferrari', model: 'F8 Spider', price: 262000, colour: 'giallo modena'}, | |
{id: 3, make: 'Lamborghini', model: 'Aventador S', price: 329400, colour: 'blu le mans'}, | |
{id: 4, make: 'Bugatti', model: 'Chiron Pur Sport', price: 3000000, colour: 'blue'}, | |
{id: 5, make: 'McLaren', model: 'New GT', price: 203000, colour: 'helios orange'}, | |
{id: 6, make: 'Ferrari', model: 'F8 Spider', price: 262000, colour: 'giallo modena'}, | |
{id: 7, make: 'Ferrari', model: 'F8 Spider', price: 262000, colour: 'red'}, | |
{id: 8, make: 'Bugatti', model: 'Chiron Pur Sport', price: 3000000, colour: 'red'}, | |
{id: 1, make: 'Ferrari', model: '812GTS', price: 336000, colour: 'rosso corsa'} /* duplicate */ |
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
let car = cars.reduce(function(prev, current) { | |
return prev.price < current.price ? current:prev; | |
}, {price:0}); | |
// RESULT IS: | |
{ | |
id: 4, | |
make: "Bugatti", | |
model: "Chiron Pur Sport", | |
price: 3000000, |
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
let car = cars.reduce( (prev, current) => prev.price<current.price ? current:prev, {price:0}); |
OlderNewer