keymasterviriya1150

getNonDuplicateItemsV2

Jul 18th, 2023
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @param {Array<string|number>} employeeList
  3.  * @param {Array<string|number>} aipEmployeeList
  4.  */
  5. const getNonDuplicateItems = (employeeList, aipEmployeeList) => {
  6.   const resultList = new Set();
  7.   if (!employeeList.length) return [];
  8.   if (!aipEmployeeList.length) return employeeList;
  9.   for (let i = 0; i < employeeList.length; i++) {
  10.     const isDuplicate = aipEmployeeList.indexOf(employeeList[i]) > -1;
  11.     if (!isDuplicate) resultList.add(employeeList[i]);
  12.   }
  13.   return [...resultList];
  14. };
  15.  
  16. console.log("=====case 1");
  17. let a = ["a", "b", "c"];
  18.  
  19. let b = ["a", "b", "c", "d"];
  20. console.log(getNonDuplicateItems(a, b));
  21. console.log("====case 2");
  22. 1;
  23. a = ["a", "b", "c", "d"];
  24. b = ["a", "b", "c"];
  25. console.log(getNonDuplicateItems(a, b));
  26. console.log("====case 3");
  27. a = ["a", "b", "c", "d", "d", "d"];
  28. b = ["a", "b", "c", "88"];
  29. console.log(getNonDuplicateItems(a, b));
  30. console.log("====case 4");
  31. a = ["a", "b", "c"];
  32. b = ["a", "b", "c"];
  33. console.log(getNonDuplicateItems(a, b));
  34. console.log("====case 5");
  35. a = [];
  36. b = ["a", "b", "c"];
  37. console.log(getNonDuplicateItems(a, b));
  38. console.log("====case 6");
  39. a = ["a", "b", "c"];
  40. b = [];
  41. console.log(getNonDuplicateItems(a, b));
  42.  
Advertisement
Add Comment
Please, Sign In to add comment