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
/** | |
* Задача — реализовать строковый буфер на функциях в JavaScript, со следующим синтаксисом: | |
Создание объекта: var buffer = makeBuffer();. | |
Вызов makeBuffer должен возвращать такую функцию buffer, которая при вызове buffer(value) добавляет значение в некоторое | |
внутреннее хранилище, а при вызове без аргументов buffer() — возвращает его. | |
* @example http://plnkr.co/edit/aOwEwSKX2fpwURBVmOqN?p=preview | |
* */ | |
function makeBuffer() { | |
var text = ''; | |
var buffer = function(value) { |
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 getLastDayOfMonth(year, month) { | |
var currentMounth = new Date(year, month); | |
var nextMounth = new Date(year, month + 1); | |
var result = (nextMounth - currentMounth)/86400000; | |
return result; | |
} | |
/* | |
Лучшее решение | |
function getLastDayOfMonth(year, month) { |
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 getDateAgo(date, days) { | |
var newDate = new Date(date); | |
newDate.setDate(newDate.getDate() - days) | |
return newDate.getDate(); | |
} |
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 getWeekDay(date) { | |
var days = ['вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб']; | |
var result; | |
result = days[date.getDay()]; | |
return result; | |
} |
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 camelize(str) { | |
var arr = str.split('-'); | |
for (var i = 1; i < arr.length; i++) { | |
arr[i]= arr[i][0].toUpperCase() + arr[i].slice(1); | |
} | |
str = arr.join(''); | |
return str; | |
} |
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 eratosfen(maxNubm) { | |
var arr = []; | |
var p = 2; | |
//Создаем массив заданной длины | |
for (var i = 2; i < maxNubm; i++) { | |
arr[i] = true | |
} | |
while (p * p < maxNubm) { | |
// Производим "зачеркивание" чисел по "p" |
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 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; |
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 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 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 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; |