Перекладывание бумажек без indexOf().

Мой вариант без применения методов массива (только разрешенный push) :grinning:

  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 лайк

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 лайка

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
}