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
/** | |
* usage: NAMESPACE.addFocusInEvent($node, listener); | |
* replace comments containing [code] with your code | |
*/ | |
(function(NAMESPACE, global){ | |
var document = global.document, | |
$body = document.body, | |
focusInEvent = 'focusin', | |
focusOutEvent = 'focusout', | |
$testInputContainer, |
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 checkControlSumJuridical(value){ | |
var code = value.split(''), | |
numericValue = +value, | |
x; | |
if ((numericValue < 30000000) || (numericValue > 60000000)){ | |
x = code[0] + code[1] * 2 + code[2] * 3 + code[3] * 4 + code[4] * 5 + code[5] * 6 + code[6] * 7; | |
} else{ | |
x = code[0] * 7 + code[1] + code[2] * 2 + code[3] * 3 + code[4] * 4 + code[5] * 5 + code[6] * 6; | |
} |
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 checkControlSumPhysical(value){ | |
var code = value.split(''), | |
x; | |
x = code[0] * (-1) + code[1] * 5 + code[2] * 7 + code[3] * 9 + code[4] * 4 + code[5] * 6 + code[6] * 10 + code[7] * 5 + code[8] * 7; | |
if (x % 11 === 10){ | |
x = (x % 11) % 10; | |
} else{ | |
x = x - (11 * Math.floor(x / 11)); | |
} | |
return +code[9] === x; |
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
/** | |
* bind polyfill by Mozilla | |
* from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind | |
*/ | |
if (!Function.prototype.bind) { | |
Function.prototype.bind = function (oThis) { | |
if (typeof this !== "function") { | |
// closest thing possible to the ECMAScript 5 | |
// internal IsCallable function | |
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); |
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
/* Fisher–Yates shuffle */ | |
function shuffle(array) { | |
var m = array.length, t, i; | |
while (m) { | |
i = Math.floor(Math.random() * m--); | |
t = array[m]; | |
array[m] = array[i]; | |
array[i] = t; | |
} | |
return array; |
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
/** | |
* @param {object} NS namespace (window by default) | |
*/ | |
(function(NS){ | |
NS = NS || window; | |
NS.getRandom = function(){ | |
return Math.random(); | |
}; |
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
/** | |
* @param {object} NS namespace (window by default) | |
*/ | |
(function(NS){ | |
NS = NS || window; | |
/** | |
* Returns option from cases with the correct ending according to passed number | |
* | |
* @param {Number} num number |
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
let compare = (n1, n2) => n1 - n2; | |
let bubbleSort = (arr, cmp = compare) => { | |
for (let i = 0; i < arr.length; i++) { | |
for (var j = i; j > 0; j--) { | |
if (cmp(arr[j], arr[j - 1]) < 0) { | |
arr[j], arr[j - 1] = arr[j - 1], arr[j]; | |
} | |
} | |
} |
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
let insertionSort = (arr) => { | |
for (let i = 0; i < a.length; i++) { | |
let toCmp = arr[i]; | |
for (let j = i; j > 0 && toCmp < a[j - 1]; j--) | |
arr[j] = a[j - 1]; | |
arr[j] = toCmp; | |
} | |
return arr; | |
} |
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 selectionSort = function (a) { | |
for (let i = -1; ++i < a.length;) { | |
for (let m = j = i; ++j < a.length;) { | |
if (a[m] > a[j]) m = j; | |
} | |
a[m], a[i] = a[i], a[m]; | |
} | |
return a; | |
} |
OlderNewer