Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 713 Bytes

5-remove-duplicates-from-list.md

File metadata and controls

40 lines (35 loc) · 713 Bytes

Problem:

Define a function that removes duplicates from an array of numbers and returns it as a result.

The order of the sequence has to stay the same.

Solution

function distinct(a) {
  return Array.from(new Set(a));
}
function distinct(a) {
  return [...new Set(a)];
}
function distinct(a) {
  return a.filter((item, index) => a.indexOf(item) === index);
}
function distinct(a) {
  const result = [];
  a.map(item => {
    if(!result.includes(item)) {
      result.push(item);
    } 
  })
  return result
}
function distinct(a) {
  return a.reduce((a, c) => a.includes(c) ? a : [...a, c], []);
}