This is my attempt at writing a JavaScript program to sort the contents of the data
array based on data classification. The final data should be stored as the sortedData
object which should have arrays assigned to its properties. Each property is an array of items that meet the data classification guidelines. However, my program doesn't seem to be working. Can someone please explain what's going on?
let data = [
538, 922, "725", false, 733, 170, 294, "336", false, "538",
79, 390, true, "816", "50", 920, "845", "728", "133",
"468", false, true, 520, 747, false, "540", true, true,
"262", 625, "614", 316, "978", "865", "506", 552, 187,
"444", 676, 544, 840, 691, "50", 21, "926", "10", 37,
"704", "36", 978, 830, 438, true, "713", 497, "371", 243,
638, 454, 291, "185", "941", "581", 336, 458, "585", false,
870, "639", "360", 599, "644", "767", 878, "646", 117,
"933", 48, 934, "155", "749", 808, 922, 94, "360", "395",
false, 407, true, false, "97", "233", 70, "609", false,
false, "13", "698", 797, "789"
];
let sortedData = {
stringArray: 0,
booleanArray: 0,
numberArray: 0,
}
for (let i = 0; i < data.length; i++) {
if (typeof data[i] == 'string') {
sortedData.stringArray[i] = data[i];
} else if (typeof data[i] == 'boolean') {
sortedData.booleanArray[i] = data[i];
} else if (typeof data[i] == 'number') {
sortedData.numberArray[i] = data[i];
}
}