Created
October 25, 2017 23:51
-
-
Save pmkhoa/e492e68e1509cc9f0a2982d509f3e7d7 to your computer and use it in GitHub Desktop.
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
export default function filterTenants(tenants, search) { | |
return tenants.filter(tenant => { | |
let hasFound = false | |
// For convenient, we allow user to search tenant by name & code | |
if ( | |
tenant.name.toLowerCase().includes(search) || | |
tenant.code.toLowerCase().includes(search) | |
) { | |
hasFound = true | |
} | |
// When there is a children, call filterTenants to find other matches. | |
if (Array.isArray(tenant.children) && tenant.children.length > 0) { | |
// Create temp to hold recursive result. | |
const temp = filterTenants(tenant.children, search) | |
if (temp.length) { | |
/* eslint-disable no-param-reassign */ | |
tenant.children = temp | |
hasFound = true | |
} | |
} | |
return hasFound | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment