Testing new methods

This commit is contained in:
Nick Playfair 2021-03-06 21:09:57 +00:00
parent eaa4a6a452
commit da07378de7

View File

@ -28,11 +28,46 @@ function partFilter(parts, category) {
R: /^R\d/, R: /^R\d/,
Q: /^((?!(R\d|C\d)).)*$/, Q: /^((?!(R\d|C\d)).)*$/,
}; };
// const allCaps = {};
// Get only Capactiors from array const filteredParts = parts.filter((part) => part.Part.match(regex[category]));
// console.log(`regex: ${regex[category]}`); return filteredParts;
const caps = parts.filter((part) => part.Part.match(regex[category])); }
return caps;
function getPartType(partName) {
// console.log(partName.Part);
if (partName.Part.match(/^C\d/) != null) {
return 'C';
// eslint-disable-next-line no-else-return
} else if (partName.Part.match(/^R\d/) != null) {
return 'R';
}
return 'Q';
}
function getJSONParts(allParts) {
const jsonParts = {};
const C = {};
const R = {};
const Q = {};
allParts.map((partEntry) => {
switch (getPartType(partEntry)) {
case 'C':
C[partEntry.Part] = partEntry.Value;
break;
case 'R':
R[partEntry.Part] = partEntry.Value;
break;
default:
Q[partEntry.Part] = partEntry.Value;
}
});
jsonParts['C'] = C;
jsonParts['R'] = R;
jsonParts['Q'] = Q;
return jsonParts;
} }
function clearTable() { function clearTable() {
@ -128,11 +163,14 @@ function makeJSON(csvString) {
Q, Q,
}; };
document.getElementById('jsonObject').innerText = JSON.stringify( // document.getElementById('jsonObject').innerText = JSON.stringify(
parts, // parts,
null, // null,
2, // 2,
); // );
// console.log(object);
// console.log(`partname test: ${getPartType(object[0])}`);
console.log(getJSONParts(object));
}) })
.catch((e) => { .catch((e) => {
console.error(e); console.error(e);