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
/* Define new prototype methods on Date object. */ | |
// Returns Date as a String in YYYY-MM-DD format. | |
Date.prototype.toISODateString = function () { | |
return this.toISOString().substr(0,10); | |
}; | |
// Returns new Date object offset `n` days from current Date object. | |
Date.prototype.toDateFromDays = function (n) { | |
n = parseInt(n) || 0; | |
var newDate = new Date(this.getTime()); |
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
Math.isPrime = function (n) { | |
if (n === 2) { return true; } | |
if (n % 2 === 0) { return false; } | |
for(let i = 3, s = Math.sqrt(n); i <= s; i += 2) { | |
if (n % i === 0) { return false; } | |
} | |
return n !== 1; | |
}; | |
// Based on this StackOverflow answer: https://stackoverflow.com/a/40200710/2502532 |
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
import React from 'react' | |
export function isComponentWithName (el, name) { | |
if (typeof name === 'string') { | |
return React.isValidElement(el) && name === getDisplayName(el) | |
} | |
const validRegEx = name instanceof RegExp ? name : new RegExp(name) | |
return React.isValidElement(el) && validRegEx.test(getDisplayName(el)) | |
} |
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 getRandomIndex(len) { | |
return Math.floor(Math.random() * Math.floor(len)); | |
} | |
function cycleArray(arr, i) { | |
return arr.slice(i).concat(arr.slice(0, i)) | |
} | |
function cycleArrayByRandomIndex() { | |
return cycleArray(arr, getRandomIndex(arr.length)) |
OlderNewer