DmanS
23.Июль.2020 13:57:01
1
Мой вариант без применения методов массива (только разрешенный push)
var getDocumentsNumbers = function (documentsName, year) {
var counter = 0;
var yearToString = String(year);
for (let i = 0; i < documentsName.length; i += 1) {
var documentName = documentsName[i];
var documentYear = [];
for (let j = documentName.length - 2; j < documentName.length; j += 1) {
documentYear.push(documentName[j]);
}
if (documentYear[0] === yearToString[2] && documentYear[1] === yearToString[3]) {
counter++;
}
}
return counter;
}
1 лайк
disa
24.Июль.2020 18:26:29
2
var documentsName =[“20122011”,“03032012”,“20122012”,“09072011”];
var year = 2012;
var numbers = 0;
function getDocumentsNumbers (documentsName, year) {
for (var i = 0; i < documentsName.length; i++) {
var remains = Number(documentsName[i]) % 10000;
if (remains == year) {
numbers++
}
}
return numbers;
}
2 лайка
const getDocumentsNumbers = (documents,years) => {
let count = 0;
for (let document of documents) {
if (document.endsWith(years) === true) {
count++;
}
}
return count;
}
2 лайка
Romeo
27.Февраль.2024 12:33:11
4
let getDocumentsNumbers = function (arr, year) {
let sum = 0
for (let i=0; i<arr.length; i++) {
let elem = ‘’
elem+=arr[i][arr[i].length-4]
elem+=arr[i][arr[i].length-3]
elem+=arr[i][arr[i].length-2]
elem+=arr[i][arr[i].length-1]
if (elem == year) {
sum++
}
}
return sum
}