Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ngOnInit() {
- const blah = [
- "division",
- [
- "blah",
- "blah1",
- [
- "division",
- "blah",
- [
- "division",
- "division",
- ]
- ],
- [
- "blah",
- "division",
- "blah"
- ]
- ]
- ];
- const flattened = this.reduce(blah);
- console.log(flattened);
- }
- public reduce(arr: any[]) {
- let out = [];
- arr.forEach((value, index) => {
- if (Array.isArray(value)) {
- out = out.concat(this.reduce(value));
- }
- if (value === 'division') {
- out = out.concat(value);
- }
- });
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment