Skip to content

Instantly share code, notes, and snippets.

View bailuobin's full-sized avatar

Luobin Bai bailuobin

View GitHub Profile
function termFreqMap(str) {
var words = str.split(' ');
var termFreq = {};
words.forEach(function(w) {
termFreq[w] = (termFreq[w] || 0) + 1;
});
return termFreq;
}
function addKeysToDict(map, dict) {
@bailuobin
bailuobin / Environment Detecter
Last active August 29, 2015 14:24
Javascript code to check if user is browsing this page on Mobile Devices
Environment = {
isAndroid : function() {
return navigator.userAgent.match(/Android/i);
},
isBlackBerry : function() {
return navigator.userAgent.match(/BlackBerry/i);
},
isIOS : function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);