SHARE
TWEET

03. Filter Employees

a guest Jan 24th, 2020 77 in 340 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(data, criteria) {
  2.   let parsed = JSON.parse(data);
  3.   let [criteriaName, criteriaValue] = criteria.split("-");
  4.  
  5.   let result = {};
  6.   let counter = 0;
  7.  
  8.   for(let item of parsed) {
  9.     let containsValue = item[criteriaName]
  10.     if (containsValue == criteriaValue) {
  11.         result[counter++] = `${item.first_name} ${item.last_name} - ${item.email}`;
  12.     }
  13.   }
  14.  
  15.   Object.entries(result).forEach(line => {
  16.     let num = line[0];
  17.     let valuesOfObject = line[1];
  18.  
  19.     console.log(
  20.       `${num}. ${valuesOfObject}`
  21.     );
  22.   });
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top