0

I have an array form a sheet looking like [X]:

Sat Mar 18 2017 00:00:00 GMT+0100 (MEZ), Sat Mar 11 2017 00:00:00 GMT+0100 (MEZ), Sat Mar 18 2017 00:00:00 GMT+0100 (MEZ), , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 

And a date looks like [Y]:

Sat Mar 18 2017 00:00:00 GMT+0100

How can i count the amount of Y in X?

The outcome should look like this:

var amountOfYinX = 2;
Steffen Bauer
  • 145
  • 1
  • 10
  • You are asking how to count duplicates in a JavaScript array. Which has already been asked: [Link to Stack Overflow question](http://stackoverflow.com/questions/19395257/how-to-count-duplicate-value-in-an-array-in-javascript) – Alan Wells Mar 14 '17 at 17:37
  • Possible duplicate of [How to count duplicate value in an array in javascript](http://stackoverflow.com/questions/19395257/how-to-count-duplicate-value-in-an-array-in-javascript) – Alan Wells Mar 14 '17 at 17:38
  • @SandyGood its nearly the same but to much and i can´t figure out how to splitt the code right – Steffen Bauer Mar 14 '17 at 17:57

1 Answers1

0

From the information that you have given, this works:

function countDupsInArray() {
  var amountOfYinX,data,i,L;

  data = ["Sat Mar 18 2017 00:00:00 GMT+0100 (MEZ)", "Sat Mar 11 2017 00:00:00 GMT+0100 (MEZ)", "Sat Mar 18 2017 00:00:00 GMT+0100 (MEZ)", , , , , ];

  amountOfYinX = 0;
  L = data.length;

  for (i=0;i<L;i++) {
    if (data[i] === "Sat Mar 18 2017 00:00:00 GMT+0100 (MEZ)") {
      amountOfYinX++;
    }
  }

  Logger.log('amountOfYinX: ' + amountOfYinX)
  return amountOfYinX;
};
Alan Wells
  • 30,746
  • 15
  • 104
  • 152
  • i tried to change the hardcoded date in the for loop generated date, but it won´t work ' var date = new Date(); var dateString = date.toString();' – Steffen Bauer Apr 09 '17 at 22:23