import { Tutorial } from '../types' ; export function fieldPassesFilter ( field , filter ) { if ( ! filter ) return true ; if ( ! field ) return false ; if ( typeof field === 'string' ) { return field . toLowerCase ( ) === filter . toLowerCase ( ) ; } return new Set ( field ) . has ( filter ) ; } export default function filterTutorials ( tutorials , format , topic , author , source ) { return tutorials . filter ( item => { const passesFormatFilter = fieldPassesFilter ( item . formats , format ) ; const passesTopicFilter = fieldPassesFilter ( item . topics , topic ) ; const passesAuthorFilter = fieldPassesFilter ( item . authors , author ) ; const passesSourceFilter = fieldPassesFilter ( item . source , source ) ; return ( passesFormatFilter && passesTopicFilter && passesAuthorFilter && passesSourceFilter ) ; } ) ; }