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 uuidv4() { | |
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, function(c) { | |
return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16); | |
}); | |
} | |
console.log(uuidv4()); | |
/* will produce. | |
"f89edcd5-0667-48eb-8939-23297025d7f3" |
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 getDiff(a, b) { | |
var i = 0; | |
var j = 0; | |
var result = ""; | |
while (j < b.length) { | |
if (a[i] != b[j] || i == a.length) { | |
result += b[j]; | |
} else { | |
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
String.prototype.hashCode = function () { | |
var hash = 0, i, chr; | |
if (this.length === 0) return hash; | |
for (i = 0; i < this.length; i++) { | |
chr = this.charCodeAt(i); | |
hash = ((hash << 5) - hash) + chr; | |
hash |= 0; // Convert to 32bit integer | |
} | |
return hash; | |
}; |
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 stristr (haystack, needle, bool) { | |
var pos = 0; | |
haystack += ''; | |
pos = haystack.toLowerCase().indexOf((needle + '').toLowerCase()); | |
if (pos == -1) { | |
return false; | |
} else { | |
if (bool) { | |
return haystack.substr(0, pos); |
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 EventBus = (function(){ | |
"use strict"; | |
var subscriptions = {}; | |
var getNextUniqueId = getIdGenerator(); | |
var Bus = { | |
subscribe: function(eventType, callback) { | |
var id = getNextUniqueId(); |
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
// specs code :: Jasmine | |
describe("Address Tests", function() { | |
it("Full Address", function() { | |
var appResponse = { | |
user: { | |
address: "120 Oak Avenue", | |
city: "Philadelphia" | |
} | |
}; |
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 wordPattern = function(pattern, str) { | |
var letters = pattern.split(''); | |
var symbols = {}; | |
var reverseSymbols = {}; | |
var words = str.split(' '); | |
if (letters.length != words.length) return false; | |
for (var i = 0; i < letters.length; ++i) { | |
var word = words[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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Template</title> | |
</head> | |
<body> | |
<div class="current-price"></div> |
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
myDictionary = { | |
datastore : [], | |
add: function(key, value) { | |
this.datastore.push({key: key, value: value}); | |
}, | |
find: function(key) { | |
for(var x = 0; x < this.datastore.length; x++) { | |
if (this.datastore[x] !== undefined && this.datastore[x].key === key) { | |
return this.datastore[x].value; | |
} |