Guest User

Untitled

a guest
Feb 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. /* Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.
  2. In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
  3. The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.
  4. */
  5.  
  6. function uniteUnique(arr) {
  7. let temp = [...arguments]; //Create array of passed arguments
  8. let newArr = [] //New array to hold unique numbers
  9. for (let obj in temp) {
  10. for (let item in temp[obj]) //Nested loop to check each (nested) array item
  11. {
  12. if (! newArr.includes(temp[obj][item])) { //check if number is not in newArr
  13. newArr.push(temp[obj][item]) //Push unique items
  14. }
  15. }
  16. }
  17. return newArr;
  18. }
  19.  
  20. uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]); //returns [1, 3, 2, 5, 4]
Add Comment
Please, Sign In to add comment