~ number: 6 ~ title: Collections, Iterators, and Meta-iterators
Navigation
~ number: 6 ~ title: Collections, Iterators, and Meta-iterators
Navigation
| /** | |
| * Converts YouTube formatted duration to seconds. | |
| * | |
| * Expects input String of the form "PT#M#S", in which the letters PT indicate | |
| * that the value specifies a period of time, and the letters M and S refer to | |
| * length in minutes and seconds, respectively. The # characters preceding the | |
| * M and S letters are both integers that specify the number of minutes (or | |
| * seconds) of the video. For example, a value of PT15M51S indicates that the | |
| * video is 15 minutes and 51 seconds long. | |
| */ |
| /** | |
| * Formats number of seconds to hh:mm:ss format. | |
| */ | |
| formatTime: function (seconds) { | |
| var minutes = Math.floor(seconds / 60), | |
| hours = Math.floor(minutes / 60), | |
| h = (hours !== 0) ? hours + ":" : "", | |
| m = (minutes % 60 !== 0) ? (minutes % 60) + ":" : ((h === "") ? "" : "00:"), | |
| s = (seconds % 60 !== 0) ? (seconds % 60) : "00"; |
| /** | |
| * | |
| * Computes the average number of students per section in the sandbox/demo API. | |
| * | |
| */ | |
| var request = require('request'); | |
| // We know that there's only one district in the dummy data from a call | |
| // to the `districts` endpoint, ie |
| function isValidUSPhoneNum(number) { | |
| // Matches valid US numbers of the form | |
| // xxx (whitespace or -) xxx (whitespace or -) xxxx | |
| var USPhoneNumRegex = /^(?:\([2-9][0-9]{2}\)(?:[\s]*|[-])|[2-9][0-9]{2}(?:[\s]*|[-]))[0-9]{3}(?:[\s]*|[-])[0-9]{4}$/; | |
| // booleanize bitch | |
| return !!number.match(USPhoneNumRegex); | |
| } |
| function isValidUSPhoneNum(number) { | |
| var USPhoneNumRegex = /^(?:\([2-9]{3}\)(?:[\s]*|[-])|[2-9]{3}(?:[\s]*|[-]))[0-9]{3}(?:[\s]*|[-])[0-9]{4}$/; | |
| // booleanize | |
| return !!number.match(USPhoneNumRegex); | |
| } |
| /** | |
| * | |
| * Little utility script to get list of all department codes | |
| * | |
| */ | |
| var request = require('request'); | |
| var async = require('async'); | |
| var _ = require('lodash'); | |
| var fs = require('fs'); |