-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83c4325
commit d532387
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const items = require('./src/items.json'); | ||
|
||
function main() { | ||
const { fileExtensions, fileNames } = items; | ||
|
||
const duplicates = [ | ||
...getDuplicates(fileExtensions), | ||
...getDuplicates(fileNames), | ||
]; | ||
|
||
if (duplicates.length > 0) { | ||
for (const [ext, type] of duplicates) { | ||
console.log(`Duplicate "${ext}" in "${type}" section`); | ||
} | ||
} else { | ||
console.log('No duplicates are found'); | ||
} | ||
} | ||
|
||
function getDuplicates(props) { | ||
const checkedItems = []; | ||
const duplicates = []; | ||
|
||
for (const type in props) { | ||
const extensions = props[type]; | ||
|
||
for (const ext of extensions) { | ||
if (checkedItems.includes(ext)) { | ||
duplicates.push([ext, type]); | ||
} else { | ||
checkedItems.push(ext); | ||
} | ||
} | ||
} | ||
|
||
return duplicates; | ||
} | ||
|
||
main(); |
This file contains 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