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 isNumeric(n) { | |
| return !isNaN(parseFloat(n)) && isFinite(n); | |
| } |
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 getDecimal(num) { | |
| var result; | |
| var initialNum = Math.abs(num); | |
| var roundedNum = Math.round(initialNum); | |
| if (roundedNum > initialNum) { | |
| result = roundedNum - initialNum - 1; | |
| result = Math.abs(result); | |
| result = +result.toFixed(10); | |
| } |
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 ucFirst(str) { | |
| // только пустая строка в логическом контексте даст false | |
| if (!str) return str; | |
| return str[0].toUpperCase() + str.slice(1); | |
| } |
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 checkSpam(str) { | |
| var firstWord = 'viagra'; | |
| var secondWord = 'xxx'; | |
| var string = str.toLowerCase(); | |
| var result; | |
| if (checkTheWord(firstWord) || checkTheWord(secondWord)) { | |
| return true; | |
| } | |
| return false; |
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 truncate(str, maxlength) { | |
| if (str.length > maxlength) { | |
| return str.slice(0, maxlength - 3) + '...'; | |
| } | |
| } |
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 isNumeric(n) { | |
| return !isNaN(parseFloat(n)) && isFinite(n) | |
| } | |
| function multiplyNumeric(obj) { | |
| for (var i in obj) { | |
| if (isNumeric(obj[i])) { | |
| obj[i] *= 2; | |
| } | |
| } |
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 isEmpty(obj) { | |
| var counter = 0; | |
| for (var key in obj) { | |
| counter++; | |
| } | |
| if (counter == 0) { | |
| return true; | |
| } | |
| else { | |
| return false; |
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 showRnd(arr) { | |
| var min = 0; | |
| var max = arr.length - 1; | |
| var rand = min + Math.floor(Math.random() * (max + 1 - min)); | |
| return arr[rand]; | |
| } |
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 find(arr, value) { | |
| var i; | |
| var searchFalse = -1; | |
| for (i = 0; i<arr.length; i++) { | |
| if (arr[i] === value) { | |
| return i; | |
| } | |
| } | |
| return searchFalse; |
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 filterRange(arr, a, b) { | |
| var i = 0; | |
| var result = []; | |
| for (i = 0; i<arr.length; i++) { | |
| if (arr[i] >= a && arr[i] <= b) { | |
| result.push(arr[i]); | |
| } | |
| } | |
| return result; |
OlderNewer