Last active
October 26, 2023 03:21
-
-
Save carwin-datarock/729259a4dae3b89422832c721952ef06 to your computer and use it in GitHub Desktop.
Code exercise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "system": "ABC123", | |
| "lastUpdated": "2022-02-15T23:47:03.769Z", | |
| "files": [ | |
| { | |
| "name": "wedge tailed eagle.jpg", | |
| "lastUpdated": "2022-02-15T23:47:03.769Z", | |
| "owner": "blueskies", | |
| "group": "blueskies", | |
| "permissions": 700 | |
| }, | |
| { | |
| "name": "galah.jpg", | |
| "lastUpdated": "2022-02-15T23:47:03.769Z", | |
| "owner": "blueskies", | |
| "group": "blueskies", | |
| "permissions": 744 | |
| }, | |
| { | |
| "name": "bin chicken.jpg", | |
| "lastUpdated": "2022-02-15T23:47:03.769Z", | |
| "owner": "trash", | |
| "group": "trash", | |
| "permissions": 777 | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "system": "ABC123", | |
| "lastUpdated": "2022-02-15T23:47:03.769Z", | |
| "files": [ | |
| { | |
| "name": "wedge tailed eagle.jpg", | |
| "lastUpdated": "2022-02-15T23:47:03.769Z", | |
| "owner": "blueskies", | |
| "group": "blueskies", | |
| "permissions": 700 | |
| }, | |
| { | |
| "name": "galah.jpg", | |
| "lastUpdated": "2022-02-15T23:47:03.769Z", | |
| "owner": "datarock", | |
| "group": "datarock", | |
| "permissions": 744 | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| const dir1 = JSON.parse(fs.readFileSync(`./code-refactor-exercise-data-system1.json`)) | |
| const dir2 = JSON.parse(fs.readFileSync('./code-refactor-exercise-data-system2.json')) | |
| console.log('file,exists,owner,group,permissions') | |
| for (const file of dir1.files) { | |
| const other = dir2.files.find(s => s.name === file.name) | |
| if (!other) { | |
| console.log(`${file.name},no,,,,,"file doesn't exist"`) | |
| continue | |
| } | |
| if (file.name != other.name) { | |
| console.log(`${file.name},no,,,,,"file doesn't exist"`) | |
| continue | |
| } | |
| if (file.owner != other.owner) { | |
| console.log(`${file.name},yes,no,,,,"owner is different"`) | |
| continue | |
| } | |
| if (file.group != other.group) { | |
| console.log(`${file.name},yes,yes,no,,"group is different"`) | |
| continue | |
| } | |
| if (file.permissions != other.permissions) { | |
| console.log(`${file.name},yes,yes,yes,no,,"permissions are different"`) | |
| continue | |
| } | |
| if (file.lastUpdated != other.lastUpdated) { | |
| console.log(`${file.name},yes,yes,yes,yes,no,"file is different"`) | |
| continue | |
| } | |
| console.log(`${file.name},yes,yes,yes,yes,yes,yes,"files are the same"`) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment