Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var people = [{
- name: 'Sandeep',
- empId: 0,
- age: 23,
- orgId: 1
- }, {
- name: 'Arjun',
- empId: 1,
- age: 25,
- orgId: 2
- }, {
- name: 'Nanha',
- empId: 3,
- age: 22,
- orgId: 1
- }, {
- name: 'Nandu',
- empId: 4,
- age: 53,
- orgId: 3
- }];
- var organizations = [{
- name: 'Razorthink',
- id: 1,
- employees: [0, 3]
- }, {
- name: 'Apple',
- id: 2,
- employees: [1]
- }, {
- name: 'Microsoft',
- id: 3,
- employees: [4]
- }];
- var inDetail = organizations.map(function(org) {
- var comp = people.filter(function(peop) {
- return org.id === peop.orgId;
- })[0];
- console.log(JSON.stringify(getNames(org.employees, people).age, null, 4));
- return org.name + " has " + org.employees.length + " employees in the record: " + getNames(org.employees, people) + " who is " + comp.age + " years old.";
- }).join('\n');
- function getNames(company, emp) {
- return company.map(function(com) {
- var names = emp.filter(function(empl) {
- if (com == empl.empId)
- return empl.name;
- })
- return names.map(function(name) {
- return {
- name: name.name,
- age: name.age
- }
- }).reduce(function(sd) {
- console.log(JSON.stringify(sd,null,4));
- return sd
- })
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement