Lulunga

Distinct Array

Jun 20th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. //Remove all repeating elements from the array.
  2. function solve(input) {
  3. let uniqueArr= new Set(input);
  4. const backToArray = [...uniqueArr]
  5. console.log(backToArray.join(' '));
  6. }
  7.  
  8. //alternative code
  9.  
  10. function solve(input) {
  11. let uniqueArr=[];
  12. for (let i = 0; i < input.length; i++) {
  13. let indexOfEl=input.indexOf(input[i]);
  14. if (i===indexOfEl) {
  15. uniqueArr.push(input[i]);
  16. }
  17. }
  18. console.log(uniqueArr.join(' '));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment