import is from "is" ; import mergeAtLevel from "./mergeAtLevel" ; import indexArticleLevels from "./indexArticleLevels" ; param { Summary } summary param { String | SummaryArticle } level return { Summary } function removeArticle ( summary , level ) { level = is . string ( level ) ? level : level . getLevel ( ) ; let parent = summary . getParent ( level ) ; let articles = parent . getArticles ( ) ; const index = articles . findIndex ( ( art ) => { return art . getLevel ( ) === level ; } ) ; if ( index === - 1 ) { return summary ; } articles = articles . remove ( index ) ; parent = parent . set ( "articles" , articles ) ; parent = indexArticleLevels ( parent ) ; return mergeAtLevel ( summary , parent . getLevel ( ) , parent ) ; } export default removeArticle ;