This file contains 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 getRandom(arr, n) { | |
var result = new Array(n), | |
len = arr.length, | |
taken = new Array(len); | |
if (n > len) | |
throw new RangeError("getRandom: more elements taken than available"); | |
while (n--) { | |
var x = Math.floor(Math.random() * len); | |
result[n] = arr[x in taken ? taken[x] : x]; | |
taken[x] = --len in taken ? taken[len] : len; |
This file contains 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 timeAgo(time){ | |
var units = [ | |
{ name: "second", limit: 60, in_seconds: 1 }, | |
{ name: "minute", limit: 3600, in_seconds: 60 }, | |
{ name: "hour", limit: 86400, in_seconds: 3600 }, | |
{ name: "day", limit: 604800, in_seconds: 86400 }, | |
{ name: "week", limit: 2629743, in_seconds: 604800 }, | |
{ name: "month", limit: 31556926, in_seconds: 2629743 }, | |
{ name: "year", limit: null, in_seconds: 31556926 } | |
]; |
This file contains 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 date = new Date(); | |
var months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; | |
console.log("The current month is " + months[date.getMonth()]); |
This file contains 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
/* | |
This function changes the datestring to the following format | |
Jan 29 2018 - 09:51 AM | |
*/ | |
function formatDate(dateString){ | |
const date = new Date(dateString); | |
const hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours(); | |
return [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ][date.getMonth()] + ' ' | |
+ (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ' | |
+ date.getFullYear() + ' - ' |
NewerOlder