When I run the following:
var months = new Set(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);
var string = "27 - 28 August 663 CE";
var words = string.split(" ");
for (var i = 0; i < words.length - 1; i++) {
words[i] += " ";
}
var array = words;
array = $.map(array, function(value){
return value.replace(/ /g, '');
});
const dates = {
days : [],
months : [],
years : [],
suffixes : []
}
for (const word of words) {
if (months.has(word)) {
dates.months.push(word);
} else if (+word < 32) {
dates.days.push(+word);
} else if (+word < 2200) {
dates.years.push(+word);
} else if (/\w+/.test(word)) {
dates.suffixes.push(word);
}
}
console.log(array);
console.log(dates);
The output is incorrect:
Object {days: Array(2), months: Array(0), years: Array(1), suffixes: Array(2)}
While if I run:
var months = new Set(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);
var words = ["27","-","28","August","663","CE"];
const dates = {
days : [],
months : [],
years : [],
suffixes : []
}
for (const word of words) {
if (months.has(word)) {
dates.months.push(word);
} else if (+word < 32) {
dates.days.push(+word);
} else if (+word < 2200) {
dates.years.push(+word);
} else if (/\w+/.test(word)) {
dates.suffixes.push(word);
}
}
console.log(dates);
The output is correct:
Object {days: Array(2), months: Array(1), years: Array(1), suffixes: Array(1)}
wordsis an array pushing into the array `dates'words[i] += " ";