Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guillaumeduhan/7df1ebbca6a990d76cd791e60046d63e to your computer and use it in GitHub Desktop.
Save guillaumeduhan/7df1ebbca6a990d76cd791e60046d63e to your computer and use it in GitHub Desktop.
Compare 2 jsons arrays
const fs = require('fs');
let rawdata = fs.readFileSync('sheets1.json');
let raw1 = JSON.parse(rawdata)
let rawdata2 = fs.readFileSync('sheets2.json');
let raw2 = JSON.parse(rawdata2)
// let data = JSON.stringify(raw1.filter(x => x !== null));
// fs.writeFileSync('sheets1.json', data);
// let data2 = JSON.stringify(raw2.filter(x => x !== null));
// fs.writeFileSync('sheets2.json', data2);
console.log(raw1.length)
console.log(raw2.length)
// 65 to find
const filtered = raw2.filter(x => !raw1.includes(x))
const mapped = filtered.map((x) => ({ 'missing': x }))
// const filtered = raw2.map(x => {
// if (!raw1.includes(x)) {
// return {
// "master-serie-missing": x
// }
// }
// })
console.log(mapped)
let data = JSON.stringify(mapped);
fs.writeFileSync('missing.json', data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment