From e40ccc2bd63069f7ff6f45eb8b4d906906e2107e Mon Sep 17 00:00:00 2001
From: Nick Playfair <nick@playfair.dev>
Date: Mon, 21 Dec 2020 21:13:24 +0000
Subject: [PATCH] Filter parts array

Remove objects that have a part value which matches the rejectedParts list
---
 .gitignore |  2 +-
 index.js   | 23 +++++++++++++++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index da3eca4..624a499 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
 .DS_Store
 ._*
 node_modules/
-
+*.csv
\ No newline at end of file
diff --git a/index.js b/index.js
index 3fc39a2..0f7e4f7 100644
--- a/index.js
+++ b/index.js
@@ -1,12 +1,31 @@
-const csvFilePath = './mkII.csv'
+const csvFilePath = './tweed57_smt.csv'
 const csv = require('csvtojson')
 
+// Which components should we remove from the BOM?
+const rejectedParts = [
+  'TP1',
+  'TP2',
+  'TP3',
+  'G',
+  'U$1',
+  'J1',
+  'J2',
+  'INPUT'
+]
+
+// Return false if the Part value of the object passed in is in the list to remove
+function isJunk (element) {
+  return !rejectedParts.includes(element.Part)
+}
+
 csv({
   delimiter: ";",
   includeColumns: /(Part|Value)/,
   ignoreEmpty: true
 })
   .fromFile(csvFilePath)
-  .then(parts => {
+  .then(jsonObj => {
+    // Create array containing only relevant parts
+    let parts = jsonObj.filter(isJunk)
     console.log(parts)
   })
\ No newline at end of file