restructuring the project
This commit is contained in:
26
src/utils/isParentOf.js
Normal file
26
src/utils/isParentOf.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @module utils
|
||||
*/
|
||||
|
||||
import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
import { Type } from '../structs/Type.js' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* Check if `parent` is a parent of `child`.
|
||||
*
|
||||
* @param {Type | Y} parent
|
||||
* @param {Type | Y} child
|
||||
* @return {Boolean} Whether `parent` is a parent of `child`.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const isParentOf = (parent, child) => {
|
||||
child = child._parent
|
||||
while (child !== null) {
|
||||
if (child === parent) {
|
||||
return true
|
||||
}
|
||||
child = child._parent
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user