Skip to content

Instantly share code, notes, and snippets.

View railsstudent's full-sized avatar
🏠
Researching third-party library

Connie Leung railsstudent

🏠
Researching third-party library
View GitHub Profile
// http://www.cs.virginia.edu/kim/courses/cs3330/notes/ConvertingFP.pdf
// https://en.wikipedia.org/wiki/Single-precision_floating-point_format
var dec2Bin = function (wholeInt) {
let binaryInt = '';
while (wholeInt > 1) {
let remainder = wholeInt % 2;
binaryInt += remainder;
wholeInt = Math.floor(wholeInt / 2);
function TicTacToe() {
// fill out the construction function
this.strategy = [5,1,3,7,9,2,4,6,8];
this.board = [ 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u' ]
this.hasWon = false;
this.player = '1'
this.play_as = ''
}
function NetworkClient (sendFunction, callback) {
this.sendFunction = sendFunction;
this.callback = callback;
this.msgIdAccumulator = [];
this.msgId = 0;
}
NetworkClient.prototype.send = function (data) {
// Could wrap data with extra information to send
this.msgId += 1;
function toChineseNumeral(num){
var numerals = {
"-":"负",
".":"点",
0:"零",
1:"一",
2:"二",
3:"三",
4:"四",
5:"五",
function decomposeHelper(sumSqr, lastRemovedNum) {
var root = Math.sqrt(sumSqr);
var rootFloor = Math.floor(root);
if (rootFloor === root) {
return [ root ];
}
// find the solution
for (var i = rootFloor; i >= 1; i--) {
function buildString(value, unit) {
if (value > 0) {
return value + ' ' + unit + (value > 1 ? 's' : '') + ', ';
}
return '';
}
function formatDuration (seconds) {
// Complete this function
if (seconds === 0) {
function traverseTCPStates(eventList){
var state = "CLOSED"; // initial state, always
// Traversal code goes here
var tcpStates = {
'CLOSED' : [{ event: 'APP_PASSIVE_OPEN', new_state: 'LISTEN' }, { event: 'APP_ACTIVE_OPEN', new_state: 'SYN_SENT'}],
'LISTEN': [ { event: 'RCV_SYN', new_state: 'SYN_RCVD' },
{ event: 'APP_SEND', new_state: 'SYN_SENT' },
{ event: 'APP_CLOSE', new_state: 'CLOSED' } ],
'SYN_RCVD': [ { event: 'APP_CLOSE', new_state: 'FIN_WAIT_1' },
{ event: 'RCV_ACK', new_state: 'ESTABLISHED' } ],
function DocumentParser(reader)
{
this.reader = reader;
this.reset();
}
DocumentParser.prototype.reset = function()
{
this.wordCount = 0;
this.charCount = 0;
function undoRedo(object) {
//var storage = object;
var actions = []; // keep track of action performed
// action schema -> { name, params, has_undone }
// for non-undo acton, example of params { key, value }
// for undo action, example of params { action, key, value }
var findLastAction = function(status) {
var lastAction = null;
for (var i = actions.length - 1; i >= 0; i--) {
// complete the function so that it returns the fastest route
function navigate(numberOfIntersections, roads, start, finish) {
var arrDrivingTimes = [];
var arrRoutes = []
// initialize driving time and route in matrixes
for (var i = 0; i < numberOfIntersections; i++) {
arrDrivingTimes.push([]);
arrRoutes.push([]);
for (var j = 0; j < numberOfIntersections; j++) {