Python | JavaScript |
---|---|
String immutable | String immutable |
Integer whole numbers Float decimals |
Number - includes NaN and Infinity |
Bigint - for integer values larger than 2^53 or less than -2^53 - in Jan 2020, not fully supported by all browsers |
|
Boolean - True and False are 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 createTrigger() { | |
// Trigger once a day | |
ScriptApp.newTrigger('getCovidDataAndUpdateSpreadSheet') | |
.timeBased() | |
.atHour(8) | |
.everyDays(1) // Frequency is required if you are using atHour() or nearMinute() | |
.create(); | |
} | |
function getCovidDataAndUpdateSpreadSheet() { |
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 getCovidDataAndUpdateSpreadSheet() { | |
var url = "http://publichealth.lacounty.gov/media/Coronavirus/locations.htm" | |
//fetch site content | |
var websiteContent = UrlFetchApp.fetch(url).getContentText(); | |
var fetchTime = Utilities.formatDate(new Date(), 'Etc/GMT', "yyyy-MM-dd HH:mm:ssZ"); // "yyyy-MM-dd'T'HH:mm:ss'Z'" | |
//extract data | |
var laCasesRegExp = new RegExp(/(Laboratory Confirmed Cases \(LCC\))([tdh<>\/]+)([0-9]+)/m); | |
var laDeathsRegExp = new RegExp(/(Deaths)([tdh<>\/]+)([0-9]+)/m); |
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
var url = "http://publichealth.lacounty.gov/media/Coronavirus/locations.htm" | |
//fetch site content | |
var websiteContent = UrlFetchApp.fetch(url).getContentText(); | |
var fetchTime = Utilities.formatDate(new Date(), 'Etc/GMT', "yyyy-MM-dd HH:mm:ssZ"); // "yyyy-MM-dd'T'HH:mm:ss'Z'" | |
Logger.log('website content: ' + websiteContent); | |
Logger.log('fetch time: ' + fetchTime); |
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
//extract data | |
var laCasesRegExp = new RegExp(/(Laboratory Confirmed Cases \(LCC\))([tdh<>\/]+)([0-9]+)/m); | |
var laDeathsRegExp = new RegExp(/(Deaths)([tdh<>\/]+)([0-9]+)/m); | |
var laCasesMatchText = laCasesRegExp.exec(websiteContent); | |
Logger.log('LA cases: ' + laCasesMatchText[3]); | |
var laDeathsMatchText = laDeathsRegExp.exec(websiteContent); | |
Logger.log('LA deaths: ' + laDeathsMatchText[3]); |
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
//Given a string, sort it in decreasing order based on the frequency of characters. | |
var frequencySort = function(s) { | |
var charFreq = {}; | |
for (var i = 0; i < s.length; i++) { | |
if(charFreq[s[i]]) { | |
charFreq[s[i]] = charFreq[s[i]] + 1; | |
} else { | |
charFreq[s[i]] = 1; |
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
//https://gist.github.com/tim-hr/c9fb047b96d9d36944cec901b7413201 | |
//GOAL: make a class called CashAmount | |
//input: accepts double values (e.g., 14.72) | |
// Note: you can do this by converting to pennies for all denominations so you are always working with integers, then converting back to a two-decimal float as needed. | |
//How to convert: multipy money by 100 REMEMBER to convert back! | |
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
//Given a string, sort it in decreasing order based on the frequency of characters. | |
var test = "Aabb"; | |
var frequencySort = function(s) { | |
var counter = {}; | |
var sortedArr = []; | |
var theStr = ""; | |
for(var i = 0; i < s.length; 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
var input; | |
while(true){ | |
input = prompt('Enter an integer greater than 0'); | |
if (input > 0){ | |
break; | |
} else if (input === null) { | |
break; | |
} | |
} |