Move getSymmetricDifference to helper file

This commit is contained in:
Sam Carlton 2022-06-11 17:04:21 -05:00
parent ce710b1f55
commit 79640781bc
2 changed files with 24 additions and 9 deletions

View file

@ -16,6 +16,7 @@ import buildDeviceList from '~/helpers/build-device-list.js'
import { saveSitemap } from '~/helpers/api/sitemap/build.js' import { saveSitemap } from '~/helpers/api/sitemap/build.js'
import { deviceSupportsApp } from '~/helpers/devices.js' import { deviceSupportsApp } from '~/helpers/devices.js'
import getListSummaryNumbers from '~/helpers/get-list-summary-numbers.js' import getListSummaryNumbers from '~/helpers/get-list-summary-numbers.js'
import { logArraysDifference } from '~/helpers/arrays.js'
import { import {
getRelatedVideos getRelatedVideos
@ -55,12 +56,7 @@ dotenv.config()
let timeRunGetListArray = 0 let timeRunGetListArray = 0
let timeRunGetListByCategories = 0 let timeRunGetListByCategories = 0
function getSymmetricDifference (a, b) {
return [
a.filter(x => !b.includes(x)),
b.filter(x => !a.includes(x))
]
}
function normalizeVersion ( rawVersion ) { function normalizeVersion ( rawVersion ) {
const containsNumbers = /\d+/.test( rawVersion ) const containsNumbers = /\d+/.test( rawVersion )
@ -528,10 +524,8 @@ class BuildLists {
if ( fileCount !== this.lists[listOptions.name].size ) { if ( fileCount !== this.lists[listOptions.name].size ) {
const listSlugs = Array.from( this.lists[listOptions.name] ).map( listEntry => listEntry.slug ) const listSlugs = Array.from( this.lists[listOptions.name] ).map( listEntry => listEntry.slug )
const fileNames = fs.readdirSync( apiListDirectory ).map( fileName => basename(fileName).split('.')[0] ) const fileNames = fs.readdirSync( apiListDirectory ).map( fileName => basename(fileName).split('.')[0] )
const difference = getSymmetricDifference( listSlugs, fileNames )
console.log( 'List difference', difference ) logArraysDifference( listSlugs, fileNames )
console.log( `List difference Count ${ difference[0].length } / ${ difference[1].length }`, )
throw new Error( `Files (${ fileCount }) don\'t match list count in ${ apiListDirectory }(${ this.lists[listOptions.name].size }).` ) throw new Error( `Files (${ fileCount }) don\'t match list count in ${ apiListDirectory }(${ this.lists[listOptions.name].size }).` )
} }

21
helpers/array.js Normal file
View file

@ -0,0 +1,21 @@
export function getSymmetricDifference (a, b) {
return [
a.filter(x => !b.includes(x)),
b.filter(x => !a.includes(x))
]
}
export function logArraysDifference (a, b) {
const [ aOnly, bOnly ] = getSymmetricDifference(a, b)
console.log( 'Missing from first list:', aOnly )
console.log( 'Missing from second list:', bOnly )
console.log( `List difference Count ${ aOnly.length } / ${ bOnly.length }`, )
return {
aOnly,
bOnly,
}
}