Remove all of the duplicate numbers in an array of numbers [duplicate]












12
















This question already has an answer here:




  • Get all unique values in a JavaScript array (remove duplicates)

    66 answers




I received this question for practice and the wording confused me, as I see 2 results that it might want.



And either way, I'd like to see both solutions.



For example, if I have an array:



let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];


I'm taking this as wanting the final result as either:



let finalResult = [1, 2, 3, 4, 5, 8, 9, 10];


OR:



let finalResult = [1, 9, 10];


The difference between the two being, one just removes any duplicate numbers and leaves the rest and the second just wants any number that isn't a duplicate.



Either way, I'd like to write two functions that does one of each.



This, given by someone else gives my second solution.



let elems = {},

arr2 = arr.filter(function (e) {
if (elems[e] === undefined) {
elems[e] = true;
return true;
}
return false;
});
console.log(arr2);


I'm not sure about a function for the first one (remove all duplicates).










share|improve this question















marked as duplicate by Jared Smith, pushkin, BlueRaja - Danny Pflughoeft, the_lotus, Moira Mar 20 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • If you're using lodash, you can use _.uniq()

    – BlueRaja - Danny Pflughoeft
    Mar 20 at 9:29






  • 1





    Further, this is asking for the inverse of Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array. Finally, this post is asking two separate questions and both have good answers elsewhere already.

    – Søren D. Ptæus
    Mar 20 at 9:51













  • To answer the question "which one is it" in a comment-answer: if you're asked to remove duplicates, I believe you should understand the first variant. The second variant removes all element that have duplicates, meaning the "original" value AND its duplicates.

    – Pierre Arlaud
    Mar 20 at 13:18
















12
















This question already has an answer here:




  • Get all unique values in a JavaScript array (remove duplicates)

    66 answers




I received this question for practice and the wording confused me, as I see 2 results that it might want.



And either way, I'd like to see both solutions.



For example, if I have an array:



let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];


I'm taking this as wanting the final result as either:



let finalResult = [1, 2, 3, 4, 5, 8, 9, 10];


OR:



let finalResult = [1, 9, 10];


The difference between the two being, one just removes any duplicate numbers and leaves the rest and the second just wants any number that isn't a duplicate.



Either way, I'd like to write two functions that does one of each.



This, given by someone else gives my second solution.



let elems = {},

arr2 = arr.filter(function (e) {
if (elems[e] === undefined) {
elems[e] = true;
return true;
}
return false;
});
console.log(arr2);


I'm not sure about a function for the first one (remove all duplicates).










share|improve this question















marked as duplicate by Jared Smith, pushkin, BlueRaja - Danny Pflughoeft, the_lotus, Moira Mar 20 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • If you're using lodash, you can use _.uniq()

    – BlueRaja - Danny Pflughoeft
    Mar 20 at 9:29






  • 1





    Further, this is asking for the inverse of Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array. Finally, this post is asking two separate questions and both have good answers elsewhere already.

    – Søren D. Ptæus
    Mar 20 at 9:51













  • To answer the question "which one is it" in a comment-answer: if you're asked to remove duplicates, I believe you should understand the first variant. The second variant removes all element that have duplicates, meaning the "original" value AND its duplicates.

    – Pierre Arlaud
    Mar 20 at 13:18














12












12








12


2







This question already has an answer here:




  • Get all unique values in a JavaScript array (remove duplicates)

    66 answers




I received this question for practice and the wording confused me, as I see 2 results that it might want.



And either way, I'd like to see both solutions.



For example, if I have an array:



let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];


I'm taking this as wanting the final result as either:



let finalResult = [1, 2, 3, 4, 5, 8, 9, 10];


OR:



let finalResult = [1, 9, 10];


The difference between the two being, one just removes any duplicate numbers and leaves the rest and the second just wants any number that isn't a duplicate.



Either way, I'd like to write two functions that does one of each.



This, given by someone else gives my second solution.



let elems = {},

arr2 = arr.filter(function (e) {
if (elems[e] === undefined) {
elems[e] = true;
return true;
}
return false;
});
console.log(arr2);


I'm not sure about a function for the first one (remove all duplicates).










share|improve this question

















This question already has an answer here:




  • Get all unique values in a JavaScript array (remove duplicates)

    66 answers




I received this question for practice and the wording confused me, as I see 2 results that it might want.



And either way, I'd like to see both solutions.



For example, if I have an array:



let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];


I'm taking this as wanting the final result as either:



let finalResult = [1, 2, 3, 4, 5, 8, 9, 10];


OR:



let finalResult = [1, 9, 10];


The difference between the two being, one just removes any duplicate numbers and leaves the rest and the second just wants any number that isn't a duplicate.



Either way, I'd like to write two functions that does one of each.



This, given by someone else gives my second solution.



let elems = {},

arr2 = arr.filter(function (e) {
if (elems[e] === undefined) {
elems[e] = true;
return true;
}
return false;
});
console.log(arr2);


I'm not sure about a function for the first one (remove all duplicates).





This question already has an answer here:




  • Get all unique values in a JavaScript array (remove duplicates)

    66 answers








javascript arrays duplicates






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 20 at 17:43









pushkin

4,613112954




4,613112954










asked Mar 20 at 7:09









mph85mph85

1279




1279




marked as duplicate by Jared Smith, pushkin, BlueRaja - Danny Pflughoeft, the_lotus, Moira Mar 20 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Jared Smith, pushkin, BlueRaja - Danny Pflughoeft, the_lotus, Moira Mar 20 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • If you're using lodash, you can use _.uniq()

    – BlueRaja - Danny Pflughoeft
    Mar 20 at 9:29






  • 1





    Further, this is asking for the inverse of Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array. Finally, this post is asking two separate questions and both have good answers elsewhere already.

    – Søren D. Ptæus
    Mar 20 at 9:51













  • To answer the question "which one is it" in a comment-answer: if you're asked to remove duplicates, I believe you should understand the first variant. The second variant removes all element that have duplicates, meaning the "original" value AND its duplicates.

    – Pierre Arlaud
    Mar 20 at 13:18



















  • If you're using lodash, you can use _.uniq()

    – BlueRaja - Danny Pflughoeft
    Mar 20 at 9:29






  • 1





    Further, this is asking for the inverse of Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array. Finally, this post is asking two separate questions and both have good answers elsewhere already.

    – Søren D. Ptæus
    Mar 20 at 9:51













  • To answer the question "which one is it" in a comment-answer: if you're asked to remove duplicates, I believe you should understand the first variant. The second variant removes all element that have duplicates, meaning the "original" value AND its duplicates.

    – Pierre Arlaud
    Mar 20 at 13:18

















If you're using lodash, you can use _.uniq()

– BlueRaja - Danny Pflughoeft
Mar 20 at 9:29





If you're using lodash, you can use _.uniq()

– BlueRaja - Danny Pflughoeft
Mar 20 at 9:29




1




1





Further, this is asking for the inverse of Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array. Finally, this post is asking two separate questions and both have good answers elsewhere already.

– Søren D. Ptæus
Mar 20 at 9:51







Further, this is asking for the inverse of Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array. Finally, this post is asking two separate questions and both have good answers elsewhere already.

– Søren D. Ptæus
Mar 20 at 9:51















To answer the question "which one is it" in a comment-answer: if you're asked to remove duplicates, I believe you should understand the first variant. The second variant removes all element that have duplicates, meaning the "original" value AND its duplicates.

– Pierre Arlaud
Mar 20 at 13:18





To answer the question "which one is it" in a comment-answer: if you're asked to remove duplicates, I believe you should understand the first variant. The second variant removes all element that have duplicates, meaning the "original" value AND its duplicates.

– Pierre Arlaud
Mar 20 at 13:18












9 Answers
9






active

oldest

votes


















20














Using Set and Array.from()






let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

console.log(Array.from(new Set(arr)));





Alternate using regex



regex explanation here






let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

let res = arr
.join(',')
.replace(/(b,w+b)(?=.*1)/ig, '')
.split(',')
.map(Number);

console.log(res);





Alternate using objects






let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

let obj = arr.reduce((acc, val) => Object.assign(acc, {
[val]: val
}), {});

console.log(Object.values(obj));








share|improve this answer

































    14














    Just use a simple array.filter one-liner:






    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
    let finalResult = arr.filter((e, i, a) => a.indexOf(e) == i).sort(function(a, b){return a - b});
    console.log(finalResult);





    You could use another filter statement if you wanted the second result:






    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
    let finalResult = arr.filter((e, i, a) => a.filter(f => f == e).length == 1).sort(function(a, b){return a - b});
    console.log(finalResult);








    share|improve this answer


























    • You could also add .sort() to sort them by numerical order: .sort(function(a, b){return a - b}) on finalresult

      – Mukyuu
      Mar 20 at 7:13











    • Yes @Mukyuu, that would also be useful

      – Jack Bashford
      Mar 20 at 7:16






    • 5





      Worth pointing out that the run time of this approach will be quadratic on the size of the input, which is probably not great unless the input arrays are known to be always fairly small.

      – Joe Lee-Moyet
      Mar 20 at 11:55






    • 1





      Most voted with multiple array#filter, array#sort and array#indexOf... That is not performant

      – Yosvel Quintero
      Mar 20 at 13:08













    • Do note that the .sort() is not necessary - the end result without the sort is still an array without any duplicate items, just in the same order as the original array. (It does make it exactly match the finalResult variable in the question though.)

      – Florrie
      Mar 20 at 14:53



















    11














    For the first part you can use Set() and Spread Syntax to remove duplicates.






    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
    let res = [...new Set(arr)]
    console.log(res)





    For the second part you can use reduce()






    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
    //to get the object with count of each number in array.
    let obj = arr.reduce((ac,a) => {
    //check if number doesnot occur before then set its count to 1
    if(!ac[a]) ac[a] = 1;
    //if number is already in object increase its count
    else ac[a]++;
    return ac;
    },{})
    //Using reduce on all the keys of object means all numbers.
    let res = Object.keys(obj).reduce((ac,a) => {
    //check if count of current number 'a' is `1` in the above object then add it into array
    if(obj[a] === 1) ac.push(+a)
    return ac;
    },)
    console.log(res)








    share|improve this answer


























    • nice appreciate that, that 2nd one looks crazy. I'm assuming the time complexity for would be less than ideal compared to other results?

      – mph85
      Mar 20 at 7:24











    • @mph85 Yes its a little complex because it doesnot go through the array again and again instead it just store all the result obj and then filter it.Its better regarding performance

      – Maheer Ali
      Mar 20 at 7:26













    • could you remind me why we need the spread operator? what happens if we don't have it? @Maheer Ali

      – mph85
      Mar 20 at 7:28













    • Is it because if we don't have it, it'll just log an object?

      – mph85
      Mar 20 at 7:29











    • @mph85 No if we will not have it. We will have a Set() inside array. We use it convert Set() to Array

      – Maheer Ali
      Mar 20 at 7:30



















    5














    You could sort the array before and filter the array by checking only one side for duplicates or both sides.






    var array = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10],
    result1,
    result2;

    array.sort((a, b) => a - b);

    result1 = array.filter((v, i, a) => a[i - 1] !== v);
    result2 = array.filter((v, i, a) => a[i - 1] !== v && a[i + 1] !== v);

    console.log(...result1);
    console.log(...result2)








    share|improve this answer
























    • thank for that, for the result1 what is going on with the a[i - 1] !== v?

      – mph85
      Mar 20 at 22:01











    • a is the array, i is the actual index, and v is the actual value. it takes the value from the index before of the actual index and looks if the values are not equal.

      – Nina Scholz
      Mar 20 at 22:03











    • ah ok, and sorry, it takes the value from the index before of the actual index? Not sure what you mean by that

      – mph85
      Mar 20 at 22:10













    • for example if you have the value 9 of the array as v, then the value before is 8.

      – Nina Scholz
      Mar 20 at 22:13











    • ah ok, thank you for that

      – mph85
      Mar 20 at 22:15





















    5














    You can create both arrays in One Go






    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
    let unique = new Set();
    let repeated = Array.from(arr.reduce((acc, curr) => {
    acc.has(curr) ? unique.delete(curr) : acc.add(curr) && unique.add(curr);
    return acc;
    }, new Set()));

    console.log(Array.from(unique))
    console.log(repeated)








    share|improve this answer



















    • 1





      Nice one mate +1

      – Maheer Ali
      Mar 20 at 7:47











    • I wonder if the ternary plus && could be unclear though (x?y:z&&w)? It's not obvious to me how JS's order of operations would handle that, and I wonder if you could get across the same logic and reasoning by using if/else?

      – Florrie
      Mar 20 at 14:56



















    5














    You can use Array.prototype.reduce() create a hash object where the keys are the numbers in the array and the values are going to be the the repeated occurrence of numbers in the arr array variable..



    Then using Object.keys():




    • Remove all duplicates Object.keys(hash)

    • Remove all duplicates but filtering with Array.prototype.filter() to get the numbers with only one occurrence


    Code:






    const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
    const hash = arr.reduce((a, c) => (a[c] = (a[c] || 0) + 1, a), {});

    // [1, 2, 3, 4, 5, 8, 9, 10];
    const finalResultOne = Object.keys(hash);

    // [1, 9, 10];
    const finalResultTwo = Object.keys(hash).filter(k => hash[k] === 1);

    console.log('finalResultOne:', ...finalResultOne);
    console.log('finalResultTwo:', ...finalResultTwo);








    share|improve this answer

































      4














      You can use closure and Map






      let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

      const build = ar => {
      const mapObj = ar.reduce((acc, e) => {
      acc.has(e) ? acc.set(e, true) : acc.set(e, false)
      return acc
      }, new Map())

      return function(hasDup = true) {
      if(hasDup) return [...mapObj.keys()]
      else return [...mapObj].filter(([key, val]) => !val).map(([k, v])=> k)
      }
      }

      const getArr = build(arr)

      console.log(getArr())
      console.log(getArr(false))








      share|improve this answer































        4














        As many other have said, the first one is just [...new Set(arr)]



        For the second, just filter out those that occur more than once:




        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

        const count = (arr, e) => arr.filter(n => n == e).length

        const unique = arr => arr.filter(e => count(arr, e) < 2)

        console.log(unique(arr));








        share|improve this answer































          2

















          var arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
          var map = {};
          var finalResult = ;
          for (var i = 0; i < arr.length; i++) {
          if (!map.hasOwnProperty(arr[i])) {
          map[arr[i]] = true;
          finalResult.push(arr[i]);
          }
          }

          //if you need it sorted otherwise it will be in order
          finalResult.sort(function(a, b) {
          return a - b
          });

          console.log(finalResult);








          share|improve this answer
































            9 Answers
            9






            active

            oldest

            votes








            9 Answers
            9






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            20














            Using Set and Array.from()






            let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

            console.log(Array.from(new Set(arr)));





            Alternate using regex



            regex explanation here






            let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

            let res = arr
            .join(',')
            .replace(/(b,w+b)(?=.*1)/ig, '')
            .split(',')
            .map(Number);

            console.log(res);





            Alternate using objects






            let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

            let obj = arr.reduce((acc, val) => Object.assign(acc, {
            [val]: val
            }), {});

            console.log(Object.values(obj));








            share|improve this answer






























              20














              Using Set and Array.from()






              let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

              console.log(Array.from(new Set(arr)));





              Alternate using regex



              regex explanation here






              let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

              let res = arr
              .join(',')
              .replace(/(b,w+b)(?=.*1)/ig, '')
              .split(',')
              .map(Number);

              console.log(res);





              Alternate using objects






              let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

              let obj = arr.reduce((acc, val) => Object.assign(acc, {
              [val]: val
              }), {});

              console.log(Object.values(obj));








              share|improve this answer




























                20












                20








                20







                Using Set and Array.from()






                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                console.log(Array.from(new Set(arr)));





                Alternate using regex



                regex explanation here






                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let res = arr
                .join(',')
                .replace(/(b,w+b)(?=.*1)/ig, '')
                .split(',')
                .map(Number);

                console.log(res);





                Alternate using objects






                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let obj = arr.reduce((acc, val) => Object.assign(acc, {
                [val]: val
                }), {});

                console.log(Object.values(obj));








                share|improve this answer















                Using Set and Array.from()






                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                console.log(Array.from(new Set(arr)));





                Alternate using regex



                regex explanation here






                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let res = arr
                .join(',')
                .replace(/(b,w+b)(?=.*1)/ig, '')
                .split(',')
                .map(Number);

                console.log(res);





                Alternate using objects






                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let obj = arr.reduce((acc, val) => Object.assign(acc, {
                [val]: val
                }), {});

                console.log(Object.values(obj));








                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                console.log(Array.from(new Set(arr)));





                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                console.log(Array.from(new Set(arr)));





                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let res = arr
                .join(',')
                .replace(/(b,w+b)(?=.*1)/ig, '')
                .split(',')
                .map(Number);

                console.log(res);





                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let res = arr
                .join(',')
                .replace(/(b,w+b)(?=.*1)/ig, '')
                .split(',')
                .map(Number);

                console.log(res);





                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let obj = arr.reduce((acc, val) => Object.assign(acc, {
                [val]: val
                }), {});

                console.log(Object.values(obj));





                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                let obj = arr.reduce((acc, val) => Object.assign(acc, {
                [val]: val
                }), {});

                console.log(Object.values(obj));






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 20 at 8:01

























                answered Mar 20 at 7:11









                Aswin KumarAswin Kumar

                999115




                999115

























                    14














                    Just use a simple array.filter one-liner:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.indexOf(e) == i).sort(function(a, b){return a - b});
                    console.log(finalResult);





                    You could use another filter statement if you wanted the second result:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.filter(f => f == e).length == 1).sort(function(a, b){return a - b});
                    console.log(finalResult);








                    share|improve this answer


























                    • You could also add .sort() to sort them by numerical order: .sort(function(a, b){return a - b}) on finalresult

                      – Mukyuu
                      Mar 20 at 7:13











                    • Yes @Mukyuu, that would also be useful

                      – Jack Bashford
                      Mar 20 at 7:16






                    • 5





                      Worth pointing out that the run time of this approach will be quadratic on the size of the input, which is probably not great unless the input arrays are known to be always fairly small.

                      – Joe Lee-Moyet
                      Mar 20 at 11:55






                    • 1





                      Most voted with multiple array#filter, array#sort and array#indexOf... That is not performant

                      – Yosvel Quintero
                      Mar 20 at 13:08













                    • Do note that the .sort() is not necessary - the end result without the sort is still an array without any duplicate items, just in the same order as the original array. (It does make it exactly match the finalResult variable in the question though.)

                      – Florrie
                      Mar 20 at 14:53
















                    14














                    Just use a simple array.filter one-liner:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.indexOf(e) == i).sort(function(a, b){return a - b});
                    console.log(finalResult);





                    You could use another filter statement if you wanted the second result:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.filter(f => f == e).length == 1).sort(function(a, b){return a - b});
                    console.log(finalResult);








                    share|improve this answer


























                    • You could also add .sort() to sort them by numerical order: .sort(function(a, b){return a - b}) on finalresult

                      – Mukyuu
                      Mar 20 at 7:13











                    • Yes @Mukyuu, that would also be useful

                      – Jack Bashford
                      Mar 20 at 7:16






                    • 5





                      Worth pointing out that the run time of this approach will be quadratic on the size of the input, which is probably not great unless the input arrays are known to be always fairly small.

                      – Joe Lee-Moyet
                      Mar 20 at 11:55






                    • 1





                      Most voted with multiple array#filter, array#sort and array#indexOf... That is not performant

                      – Yosvel Quintero
                      Mar 20 at 13:08













                    • Do note that the .sort() is not necessary - the end result without the sort is still an array without any duplicate items, just in the same order as the original array. (It does make it exactly match the finalResult variable in the question though.)

                      – Florrie
                      Mar 20 at 14:53














                    14












                    14








                    14







                    Just use a simple array.filter one-liner:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.indexOf(e) == i).sort(function(a, b){return a - b});
                    console.log(finalResult);





                    You could use another filter statement if you wanted the second result:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.filter(f => f == e).length == 1).sort(function(a, b){return a - b});
                    console.log(finalResult);








                    share|improve this answer















                    Just use a simple array.filter one-liner:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.indexOf(e) == i).sort(function(a, b){return a - b});
                    console.log(finalResult);





                    You could use another filter statement if you wanted the second result:






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.filter(f => f == e).length == 1).sort(function(a, b){return a - b});
                    console.log(finalResult);








                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.indexOf(e) == i).sort(function(a, b){return a - b});
                    console.log(finalResult);





                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.indexOf(e) == i).sort(function(a, b){return a - b});
                    console.log(finalResult);





                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.filter(f => f == e).length == 1).sort(function(a, b){return a - b});
                    console.log(finalResult);





                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let finalResult = arr.filter((e, i, a) => a.filter(f => f == e).length == 1).sort(function(a, b){return a - b});
                    console.log(finalResult);






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 20 at 7:20









                    Mukyuu

                    1,82431123




                    1,82431123










                    answered Mar 20 at 7:11









                    Jack BashfordJack Bashford

                    13.1k31847




                    13.1k31847













                    • You could also add .sort() to sort them by numerical order: .sort(function(a, b){return a - b}) on finalresult

                      – Mukyuu
                      Mar 20 at 7:13











                    • Yes @Mukyuu, that would also be useful

                      – Jack Bashford
                      Mar 20 at 7:16






                    • 5





                      Worth pointing out that the run time of this approach will be quadratic on the size of the input, which is probably not great unless the input arrays are known to be always fairly small.

                      – Joe Lee-Moyet
                      Mar 20 at 11:55






                    • 1





                      Most voted with multiple array#filter, array#sort and array#indexOf... That is not performant

                      – Yosvel Quintero
                      Mar 20 at 13:08













                    • Do note that the .sort() is not necessary - the end result without the sort is still an array without any duplicate items, just in the same order as the original array. (It does make it exactly match the finalResult variable in the question though.)

                      – Florrie
                      Mar 20 at 14:53



















                    • You could also add .sort() to sort them by numerical order: .sort(function(a, b){return a - b}) on finalresult

                      – Mukyuu
                      Mar 20 at 7:13











                    • Yes @Mukyuu, that would also be useful

                      – Jack Bashford
                      Mar 20 at 7:16






                    • 5





                      Worth pointing out that the run time of this approach will be quadratic on the size of the input, which is probably not great unless the input arrays are known to be always fairly small.

                      – Joe Lee-Moyet
                      Mar 20 at 11:55






                    • 1





                      Most voted with multiple array#filter, array#sort and array#indexOf... That is not performant

                      – Yosvel Quintero
                      Mar 20 at 13:08













                    • Do note that the .sort() is not necessary - the end result without the sort is still an array without any duplicate items, just in the same order as the original array. (It does make it exactly match the finalResult variable in the question though.)

                      – Florrie
                      Mar 20 at 14:53

















                    You could also add .sort() to sort them by numerical order: .sort(function(a, b){return a - b}) on finalresult

                    – Mukyuu
                    Mar 20 at 7:13





                    You could also add .sort() to sort them by numerical order: .sort(function(a, b){return a - b}) on finalresult

                    – Mukyuu
                    Mar 20 at 7:13













                    Yes @Mukyuu, that would also be useful

                    – Jack Bashford
                    Mar 20 at 7:16





                    Yes @Mukyuu, that would also be useful

                    – Jack Bashford
                    Mar 20 at 7:16




                    5




                    5





                    Worth pointing out that the run time of this approach will be quadratic on the size of the input, which is probably not great unless the input arrays are known to be always fairly small.

                    – Joe Lee-Moyet
                    Mar 20 at 11:55





                    Worth pointing out that the run time of this approach will be quadratic on the size of the input, which is probably not great unless the input arrays are known to be always fairly small.

                    – Joe Lee-Moyet
                    Mar 20 at 11:55




                    1




                    1





                    Most voted with multiple array#filter, array#sort and array#indexOf... That is not performant

                    – Yosvel Quintero
                    Mar 20 at 13:08







                    Most voted with multiple array#filter, array#sort and array#indexOf... That is not performant

                    – Yosvel Quintero
                    Mar 20 at 13:08















                    Do note that the .sort() is not necessary - the end result without the sort is still an array without any duplicate items, just in the same order as the original array. (It does make it exactly match the finalResult variable in the question though.)

                    – Florrie
                    Mar 20 at 14:53





                    Do note that the .sort() is not necessary - the end result without the sort is still an array without any duplicate items, just in the same order as the original array. (It does make it exactly match the finalResult variable in the question though.)

                    – Florrie
                    Mar 20 at 14:53











                    11














                    For the first part you can use Set() and Spread Syntax to remove duplicates.






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let res = [...new Set(arr)]
                    console.log(res)





                    For the second part you can use reduce()






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    //to get the object with count of each number in array.
                    let obj = arr.reduce((ac,a) => {
                    //check if number doesnot occur before then set its count to 1
                    if(!ac[a]) ac[a] = 1;
                    //if number is already in object increase its count
                    else ac[a]++;
                    return ac;
                    },{})
                    //Using reduce on all the keys of object means all numbers.
                    let res = Object.keys(obj).reduce((ac,a) => {
                    //check if count of current number 'a' is `1` in the above object then add it into array
                    if(obj[a] === 1) ac.push(+a)
                    return ac;
                    },)
                    console.log(res)








                    share|improve this answer


























                    • nice appreciate that, that 2nd one looks crazy. I'm assuming the time complexity for would be less than ideal compared to other results?

                      – mph85
                      Mar 20 at 7:24











                    • @mph85 Yes its a little complex because it doesnot go through the array again and again instead it just store all the result obj and then filter it.Its better regarding performance

                      – Maheer Ali
                      Mar 20 at 7:26













                    • could you remind me why we need the spread operator? what happens if we don't have it? @Maheer Ali

                      – mph85
                      Mar 20 at 7:28













                    • Is it because if we don't have it, it'll just log an object?

                      – mph85
                      Mar 20 at 7:29











                    • @mph85 No if we will not have it. We will have a Set() inside array. We use it convert Set() to Array

                      – Maheer Ali
                      Mar 20 at 7:30
















                    11














                    For the first part you can use Set() and Spread Syntax to remove duplicates.






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let res = [...new Set(arr)]
                    console.log(res)





                    For the second part you can use reduce()






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    //to get the object with count of each number in array.
                    let obj = arr.reduce((ac,a) => {
                    //check if number doesnot occur before then set its count to 1
                    if(!ac[a]) ac[a] = 1;
                    //if number is already in object increase its count
                    else ac[a]++;
                    return ac;
                    },{})
                    //Using reduce on all the keys of object means all numbers.
                    let res = Object.keys(obj).reduce((ac,a) => {
                    //check if count of current number 'a' is `1` in the above object then add it into array
                    if(obj[a] === 1) ac.push(+a)
                    return ac;
                    },)
                    console.log(res)








                    share|improve this answer


























                    • nice appreciate that, that 2nd one looks crazy. I'm assuming the time complexity for would be less than ideal compared to other results?

                      – mph85
                      Mar 20 at 7:24











                    • @mph85 Yes its a little complex because it doesnot go through the array again and again instead it just store all the result obj and then filter it.Its better regarding performance

                      – Maheer Ali
                      Mar 20 at 7:26













                    • could you remind me why we need the spread operator? what happens if we don't have it? @Maheer Ali

                      – mph85
                      Mar 20 at 7:28













                    • Is it because if we don't have it, it'll just log an object?

                      – mph85
                      Mar 20 at 7:29











                    • @mph85 No if we will not have it. We will have a Set() inside array. We use it convert Set() to Array

                      – Maheer Ali
                      Mar 20 at 7:30














                    11












                    11








                    11







                    For the first part you can use Set() and Spread Syntax to remove duplicates.






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let res = [...new Set(arr)]
                    console.log(res)





                    For the second part you can use reduce()






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    //to get the object with count of each number in array.
                    let obj = arr.reduce((ac,a) => {
                    //check if number doesnot occur before then set its count to 1
                    if(!ac[a]) ac[a] = 1;
                    //if number is already in object increase its count
                    else ac[a]++;
                    return ac;
                    },{})
                    //Using reduce on all the keys of object means all numbers.
                    let res = Object.keys(obj).reduce((ac,a) => {
                    //check if count of current number 'a' is `1` in the above object then add it into array
                    if(obj[a] === 1) ac.push(+a)
                    return ac;
                    },)
                    console.log(res)








                    share|improve this answer















                    For the first part you can use Set() and Spread Syntax to remove duplicates.






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let res = [...new Set(arr)]
                    console.log(res)





                    For the second part you can use reduce()






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    //to get the object with count of each number in array.
                    let obj = arr.reduce((ac,a) => {
                    //check if number doesnot occur before then set its count to 1
                    if(!ac[a]) ac[a] = 1;
                    //if number is already in object increase its count
                    else ac[a]++;
                    return ac;
                    },{})
                    //Using reduce on all the keys of object means all numbers.
                    let res = Object.keys(obj).reduce((ac,a) => {
                    //check if count of current number 'a' is `1` in the above object then add it into array
                    if(obj[a] === 1) ac.push(+a)
                    return ac;
                    },)
                    console.log(res)








                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let res = [...new Set(arr)]
                    console.log(res)





                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let res = [...new Set(arr)]
                    console.log(res)





                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    //to get the object with count of each number in array.
                    let obj = arr.reduce((ac,a) => {
                    //check if number doesnot occur before then set its count to 1
                    if(!ac[a]) ac[a] = 1;
                    //if number is already in object increase its count
                    else ac[a]++;
                    return ac;
                    },{})
                    //Using reduce on all the keys of object means all numbers.
                    let res = Object.keys(obj).reduce((ac,a) => {
                    //check if count of current number 'a' is `1` in the above object then add it into array
                    if(obj[a] === 1) ac.push(+a)
                    return ac;
                    },)
                    console.log(res)





                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    //to get the object with count of each number in array.
                    let obj = arr.reduce((ac,a) => {
                    //check if number doesnot occur before then set its count to 1
                    if(!ac[a]) ac[a] = 1;
                    //if number is already in object increase its count
                    else ac[a]++;
                    return ac;
                    },{})
                    //Using reduce on all the keys of object means all numbers.
                    let res = Object.keys(obj).reduce((ac,a) => {
                    //check if count of current number 'a' is `1` in the above object then add it into array
                    if(obj[a] === 1) ac.push(+a)
                    return ac;
                    },)
                    console.log(res)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 20 at 15:53

























                    answered Mar 20 at 7:18









                    Maheer AliMaheer Ali

                    7,335619




                    7,335619













                    • nice appreciate that, that 2nd one looks crazy. I'm assuming the time complexity for would be less than ideal compared to other results?

                      – mph85
                      Mar 20 at 7:24











                    • @mph85 Yes its a little complex because it doesnot go through the array again and again instead it just store all the result obj and then filter it.Its better regarding performance

                      – Maheer Ali
                      Mar 20 at 7:26













                    • could you remind me why we need the spread operator? what happens if we don't have it? @Maheer Ali

                      – mph85
                      Mar 20 at 7:28













                    • Is it because if we don't have it, it'll just log an object?

                      – mph85
                      Mar 20 at 7:29











                    • @mph85 No if we will not have it. We will have a Set() inside array. We use it convert Set() to Array

                      – Maheer Ali
                      Mar 20 at 7:30



















                    • nice appreciate that, that 2nd one looks crazy. I'm assuming the time complexity for would be less than ideal compared to other results?

                      – mph85
                      Mar 20 at 7:24











                    • @mph85 Yes its a little complex because it doesnot go through the array again and again instead it just store all the result obj and then filter it.Its better regarding performance

                      – Maheer Ali
                      Mar 20 at 7:26













                    • could you remind me why we need the spread operator? what happens if we don't have it? @Maheer Ali

                      – mph85
                      Mar 20 at 7:28













                    • Is it because if we don't have it, it'll just log an object?

                      – mph85
                      Mar 20 at 7:29











                    • @mph85 No if we will not have it. We will have a Set() inside array. We use it convert Set() to Array

                      – Maheer Ali
                      Mar 20 at 7:30

















                    nice appreciate that, that 2nd one looks crazy. I'm assuming the time complexity for would be less than ideal compared to other results?

                    – mph85
                    Mar 20 at 7:24





                    nice appreciate that, that 2nd one looks crazy. I'm assuming the time complexity for would be less than ideal compared to other results?

                    – mph85
                    Mar 20 at 7:24













                    @mph85 Yes its a little complex because it doesnot go through the array again and again instead it just store all the result obj and then filter it.Its better regarding performance

                    – Maheer Ali
                    Mar 20 at 7:26







                    @mph85 Yes its a little complex because it doesnot go through the array again and again instead it just store all the result obj and then filter it.Its better regarding performance

                    – Maheer Ali
                    Mar 20 at 7:26















                    could you remind me why we need the spread operator? what happens if we don't have it? @Maheer Ali

                    – mph85
                    Mar 20 at 7:28







                    could you remind me why we need the spread operator? what happens if we don't have it? @Maheer Ali

                    – mph85
                    Mar 20 at 7:28















                    Is it because if we don't have it, it'll just log an object?

                    – mph85
                    Mar 20 at 7:29





                    Is it because if we don't have it, it'll just log an object?

                    – mph85
                    Mar 20 at 7:29













                    @mph85 No if we will not have it. We will have a Set() inside array. We use it convert Set() to Array

                    – Maheer Ali
                    Mar 20 at 7:30





                    @mph85 No if we will not have it. We will have a Set() inside array. We use it convert Set() to Array

                    – Maheer Ali
                    Mar 20 at 7:30











                    5














                    You could sort the array before and filter the array by checking only one side for duplicates or both sides.






                    var array = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10],
                    result1,
                    result2;

                    array.sort((a, b) => a - b);

                    result1 = array.filter((v, i, a) => a[i - 1] !== v);
                    result2 = array.filter((v, i, a) => a[i - 1] !== v && a[i + 1] !== v);

                    console.log(...result1);
                    console.log(...result2)








                    share|improve this answer
























                    • thank for that, for the result1 what is going on with the a[i - 1] !== v?

                      – mph85
                      Mar 20 at 22:01











                    • a is the array, i is the actual index, and v is the actual value. it takes the value from the index before of the actual index and looks if the values are not equal.

                      – Nina Scholz
                      Mar 20 at 22:03











                    • ah ok, and sorry, it takes the value from the index before of the actual index? Not sure what you mean by that

                      – mph85
                      Mar 20 at 22:10













                    • for example if you have the value 9 of the array as v, then the value before is 8.

                      – Nina Scholz
                      Mar 20 at 22:13











                    • ah ok, thank you for that

                      – mph85
                      Mar 20 at 22:15


















                    5














                    You could sort the array before and filter the array by checking only one side for duplicates or both sides.






                    var array = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10],
                    result1,
                    result2;

                    array.sort((a, b) => a - b);

                    result1 = array.filter((v, i, a) => a[i - 1] !== v);
                    result2 = array.filter((v, i, a) => a[i - 1] !== v && a[i + 1] !== v);

                    console.log(...result1);
                    console.log(...result2)








                    share|improve this answer
























                    • thank for that, for the result1 what is going on with the a[i - 1] !== v?

                      – mph85
                      Mar 20 at 22:01











                    • a is the array, i is the actual index, and v is the actual value. it takes the value from the index before of the actual index and looks if the values are not equal.

                      – Nina Scholz
                      Mar 20 at 22:03











                    • ah ok, and sorry, it takes the value from the index before of the actual index? Not sure what you mean by that

                      – mph85
                      Mar 20 at 22:10













                    • for example if you have the value 9 of the array as v, then the value before is 8.

                      – Nina Scholz
                      Mar 20 at 22:13











                    • ah ok, thank you for that

                      – mph85
                      Mar 20 at 22:15
















                    5












                    5








                    5







                    You could sort the array before and filter the array by checking only one side for duplicates or both sides.






                    var array = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10],
                    result1,
                    result2;

                    array.sort((a, b) => a - b);

                    result1 = array.filter((v, i, a) => a[i - 1] !== v);
                    result2 = array.filter((v, i, a) => a[i - 1] !== v && a[i + 1] !== v);

                    console.log(...result1);
                    console.log(...result2)








                    share|improve this answer













                    You could sort the array before and filter the array by checking only one side for duplicates or both sides.






                    var array = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10],
                    result1,
                    result2;

                    array.sort((a, b) => a - b);

                    result1 = array.filter((v, i, a) => a[i - 1] !== v);
                    result2 = array.filter((v, i, a) => a[i - 1] !== v && a[i + 1] !== v);

                    console.log(...result1);
                    console.log(...result2)








                    var array = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10],
                    result1,
                    result2;

                    array.sort((a, b) => a - b);

                    result1 = array.filter((v, i, a) => a[i - 1] !== v);
                    result2 = array.filter((v, i, a) => a[i - 1] !== v && a[i + 1] !== v);

                    console.log(...result1);
                    console.log(...result2)





                    var array = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10],
                    result1,
                    result2;

                    array.sort((a, b) => a - b);

                    result1 = array.filter((v, i, a) => a[i - 1] !== v);
                    result2 = array.filter((v, i, a) => a[i - 1] !== v && a[i + 1] !== v);

                    console.log(...result1);
                    console.log(...result2)






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 20 at 7:34









                    Nina ScholzNina Scholz

                    193k15106177




                    193k15106177













                    • thank for that, for the result1 what is going on with the a[i - 1] !== v?

                      – mph85
                      Mar 20 at 22:01











                    • a is the array, i is the actual index, and v is the actual value. it takes the value from the index before of the actual index and looks if the values are not equal.

                      – Nina Scholz
                      Mar 20 at 22:03











                    • ah ok, and sorry, it takes the value from the index before of the actual index? Not sure what you mean by that

                      – mph85
                      Mar 20 at 22:10













                    • for example if you have the value 9 of the array as v, then the value before is 8.

                      – Nina Scholz
                      Mar 20 at 22:13











                    • ah ok, thank you for that

                      – mph85
                      Mar 20 at 22:15





















                    • thank for that, for the result1 what is going on with the a[i - 1] !== v?

                      – mph85
                      Mar 20 at 22:01











                    • a is the array, i is the actual index, and v is the actual value. it takes the value from the index before of the actual index and looks if the values are not equal.

                      – Nina Scholz
                      Mar 20 at 22:03











                    • ah ok, and sorry, it takes the value from the index before of the actual index? Not sure what you mean by that

                      – mph85
                      Mar 20 at 22:10













                    • for example if you have the value 9 of the array as v, then the value before is 8.

                      – Nina Scholz
                      Mar 20 at 22:13











                    • ah ok, thank you for that

                      – mph85
                      Mar 20 at 22:15



















                    thank for that, for the result1 what is going on with the a[i - 1] !== v?

                    – mph85
                    Mar 20 at 22:01





                    thank for that, for the result1 what is going on with the a[i - 1] !== v?

                    – mph85
                    Mar 20 at 22:01













                    a is the array, i is the actual index, and v is the actual value. it takes the value from the index before of the actual index and looks if the values are not equal.

                    – Nina Scholz
                    Mar 20 at 22:03





                    a is the array, i is the actual index, and v is the actual value. it takes the value from the index before of the actual index and looks if the values are not equal.

                    – Nina Scholz
                    Mar 20 at 22:03













                    ah ok, and sorry, it takes the value from the index before of the actual index? Not sure what you mean by that

                    – mph85
                    Mar 20 at 22:10







                    ah ok, and sorry, it takes the value from the index before of the actual index? Not sure what you mean by that

                    – mph85
                    Mar 20 at 22:10















                    for example if you have the value 9 of the array as v, then the value before is 8.

                    – Nina Scholz
                    Mar 20 at 22:13





                    for example if you have the value 9 of the array as v, then the value before is 8.

                    – Nina Scholz
                    Mar 20 at 22:13













                    ah ok, thank you for that

                    – mph85
                    Mar 20 at 22:15







                    ah ok, thank you for that

                    – mph85
                    Mar 20 at 22:15













                    5














                    You can create both arrays in One Go






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let unique = new Set();
                    let repeated = Array.from(arr.reduce((acc, curr) => {
                    acc.has(curr) ? unique.delete(curr) : acc.add(curr) && unique.add(curr);
                    return acc;
                    }, new Set()));

                    console.log(Array.from(unique))
                    console.log(repeated)








                    share|improve this answer



















                    • 1





                      Nice one mate +1

                      – Maheer Ali
                      Mar 20 at 7:47











                    • I wonder if the ternary plus && could be unclear though (x?y:z&&w)? It's not obvious to me how JS's order of operations would handle that, and I wonder if you could get across the same logic and reasoning by using if/else?

                      – Florrie
                      Mar 20 at 14:56
















                    5














                    You can create both arrays in One Go






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let unique = new Set();
                    let repeated = Array.from(arr.reduce((acc, curr) => {
                    acc.has(curr) ? unique.delete(curr) : acc.add(curr) && unique.add(curr);
                    return acc;
                    }, new Set()));

                    console.log(Array.from(unique))
                    console.log(repeated)








                    share|improve this answer



















                    • 1





                      Nice one mate +1

                      – Maheer Ali
                      Mar 20 at 7:47











                    • I wonder if the ternary plus && could be unclear though (x?y:z&&w)? It's not obvious to me how JS's order of operations would handle that, and I wonder if you could get across the same logic and reasoning by using if/else?

                      – Florrie
                      Mar 20 at 14:56














                    5












                    5








                    5







                    You can create both arrays in One Go






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let unique = new Set();
                    let repeated = Array.from(arr.reduce((acc, curr) => {
                    acc.has(curr) ? unique.delete(curr) : acc.add(curr) && unique.add(curr);
                    return acc;
                    }, new Set()));

                    console.log(Array.from(unique))
                    console.log(repeated)








                    share|improve this answer













                    You can create both arrays in One Go






                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let unique = new Set();
                    let repeated = Array.from(arr.reduce((acc, curr) => {
                    acc.has(curr) ? unique.delete(curr) : acc.add(curr) && unique.add(curr);
                    return acc;
                    }, new Set()));

                    console.log(Array.from(unique))
                    console.log(repeated)








                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let unique = new Set();
                    let repeated = Array.from(arr.reduce((acc, curr) => {
                    acc.has(curr) ? unique.delete(curr) : acc.add(curr) && unique.add(curr);
                    return acc;
                    }, new Set()));

                    console.log(Array.from(unique))
                    console.log(repeated)





                    let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    let unique = new Set();
                    let repeated = Array.from(arr.reduce((acc, curr) => {
                    acc.has(curr) ? unique.delete(curr) : acc.add(curr) && unique.add(curr);
                    return acc;
                    }, new Set()));

                    console.log(Array.from(unique))
                    console.log(repeated)






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 20 at 7:35









                    AZ_AZ_

                    656210




                    656210








                    • 1





                      Nice one mate +1

                      – Maheer Ali
                      Mar 20 at 7:47











                    • I wonder if the ternary plus && could be unclear though (x?y:z&&w)? It's not obvious to me how JS's order of operations would handle that, and I wonder if you could get across the same logic and reasoning by using if/else?

                      – Florrie
                      Mar 20 at 14:56














                    • 1





                      Nice one mate +1

                      – Maheer Ali
                      Mar 20 at 7:47











                    • I wonder if the ternary plus && could be unclear though (x?y:z&&w)? It's not obvious to me how JS's order of operations would handle that, and I wonder if you could get across the same logic and reasoning by using if/else?

                      – Florrie
                      Mar 20 at 14:56








                    1




                    1





                    Nice one mate +1

                    – Maheer Ali
                    Mar 20 at 7:47





                    Nice one mate +1

                    – Maheer Ali
                    Mar 20 at 7:47













                    I wonder if the ternary plus && could be unclear though (x?y:z&&w)? It's not obvious to me how JS's order of operations would handle that, and I wonder if you could get across the same logic and reasoning by using if/else?

                    – Florrie
                    Mar 20 at 14:56





                    I wonder if the ternary plus && could be unclear though (x?y:z&&w)? It's not obvious to me how JS's order of operations would handle that, and I wonder if you could get across the same logic and reasoning by using if/else?

                    – Florrie
                    Mar 20 at 14:56











                    5














                    You can use Array.prototype.reduce() create a hash object where the keys are the numbers in the array and the values are going to be the the repeated occurrence of numbers in the arr array variable..



                    Then using Object.keys():




                    • Remove all duplicates Object.keys(hash)

                    • Remove all duplicates but filtering with Array.prototype.filter() to get the numbers with only one occurrence


                    Code:






                    const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                    const hash = arr.reduce((a, c) => (a[c] = (a[c] || 0) + 1, a), {});

                    // [1, 2, 3, 4, 5, 8, 9, 10];
                    const finalResultOne = Object.keys(hash);

                    // [1, 9, 10];
                    const finalResultTwo = Object.keys(hash).filter(k => hash[k] === 1);

                    console.log('finalResultOne:', ...finalResultOne);
                    console.log('finalResultTwo:', ...finalResultTwo);








                    share|improve this answer






























                      5














                      You can use Array.prototype.reduce() create a hash object where the keys are the numbers in the array and the values are going to be the the repeated occurrence of numbers in the arr array variable..



                      Then using Object.keys():




                      • Remove all duplicates Object.keys(hash)

                      • Remove all duplicates but filtering with Array.prototype.filter() to get the numbers with only one occurrence


                      Code:






                      const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                      const hash = arr.reduce((a, c) => (a[c] = (a[c] || 0) + 1, a), {});

                      // [1, 2, 3, 4, 5, 8, 9, 10];
                      const finalResultOne = Object.keys(hash);

                      // [1, 9, 10];
                      const finalResultTwo = Object.keys(hash).filter(k => hash[k] === 1);

                      console.log('finalResultOne:', ...finalResultOne);
                      console.log('finalResultTwo:', ...finalResultTwo);








                      share|improve this answer




























                        5












                        5








                        5







                        You can use Array.prototype.reduce() create a hash object where the keys are the numbers in the array and the values are going to be the the repeated occurrence of numbers in the arr array variable..



                        Then using Object.keys():




                        • Remove all duplicates Object.keys(hash)

                        • Remove all duplicates but filtering with Array.prototype.filter() to get the numbers with only one occurrence


                        Code:






                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                        const hash = arr.reduce((a, c) => (a[c] = (a[c] || 0) + 1, a), {});

                        // [1, 2, 3, 4, 5, 8, 9, 10];
                        const finalResultOne = Object.keys(hash);

                        // [1, 9, 10];
                        const finalResultTwo = Object.keys(hash).filter(k => hash[k] === 1);

                        console.log('finalResultOne:', ...finalResultOne);
                        console.log('finalResultTwo:', ...finalResultTwo);








                        share|improve this answer















                        You can use Array.prototype.reduce() create a hash object where the keys are the numbers in the array and the values are going to be the the repeated occurrence of numbers in the arr array variable..



                        Then using Object.keys():




                        • Remove all duplicates Object.keys(hash)

                        • Remove all duplicates but filtering with Array.prototype.filter() to get the numbers with only one occurrence


                        Code:






                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                        const hash = arr.reduce((a, c) => (a[c] = (a[c] || 0) + 1, a), {});

                        // [1, 2, 3, 4, 5, 8, 9, 10];
                        const finalResultOne = Object.keys(hash);

                        // [1, 9, 10];
                        const finalResultTwo = Object.keys(hash).filter(k => hash[k] === 1);

                        console.log('finalResultOne:', ...finalResultOne);
                        console.log('finalResultTwo:', ...finalResultTwo);








                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                        const hash = arr.reduce((a, c) => (a[c] = (a[c] || 0) + 1, a), {});

                        // [1, 2, 3, 4, 5, 8, 9, 10];
                        const finalResultOne = Object.keys(hash);

                        // [1, 9, 10];
                        const finalResultTwo = Object.keys(hash).filter(k => hash[k] === 1);

                        console.log('finalResultOne:', ...finalResultOne);
                        console.log('finalResultTwo:', ...finalResultTwo);





                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                        const hash = arr.reduce((a, c) => (a[c] = (a[c] || 0) + 1, a), {});

                        // [1, 2, 3, 4, 5, 8, 9, 10];
                        const finalResultOne = Object.keys(hash);

                        // [1, 9, 10];
                        const finalResultTwo = Object.keys(hash).filter(k => hash[k] === 1);

                        console.log('finalResultOne:', ...finalResultOne);
                        console.log('finalResultTwo:', ...finalResultTwo);






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Mar 21 at 3:23

























                        answered Mar 20 at 7:47









                        Yosvel QuinteroYosvel Quintero

                        11.9k42531




                        11.9k42531























                            4














                            You can use closure and Map






                            let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                            const build = ar => {
                            const mapObj = ar.reduce((acc, e) => {
                            acc.has(e) ? acc.set(e, true) : acc.set(e, false)
                            return acc
                            }, new Map())

                            return function(hasDup = true) {
                            if(hasDup) return [...mapObj.keys()]
                            else return [...mapObj].filter(([key, val]) => !val).map(([k, v])=> k)
                            }
                            }

                            const getArr = build(arr)

                            console.log(getArr())
                            console.log(getArr(false))








                            share|improve this answer




























                              4














                              You can use closure and Map






                              let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                              const build = ar => {
                              const mapObj = ar.reduce((acc, e) => {
                              acc.has(e) ? acc.set(e, true) : acc.set(e, false)
                              return acc
                              }, new Map())

                              return function(hasDup = true) {
                              if(hasDup) return [...mapObj.keys()]
                              else return [...mapObj].filter(([key, val]) => !val).map(([k, v])=> k)
                              }
                              }

                              const getArr = build(arr)

                              console.log(getArr())
                              console.log(getArr(false))








                              share|improve this answer


























                                4












                                4








                                4







                                You can use closure and Map






                                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                const build = ar => {
                                const mapObj = ar.reduce((acc, e) => {
                                acc.has(e) ? acc.set(e, true) : acc.set(e, false)
                                return acc
                                }, new Map())

                                return function(hasDup = true) {
                                if(hasDup) return [...mapObj.keys()]
                                else return [...mapObj].filter(([key, val]) => !val).map(([k, v])=> k)
                                }
                                }

                                const getArr = build(arr)

                                console.log(getArr())
                                console.log(getArr(false))








                                share|improve this answer













                                You can use closure and Map






                                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                const build = ar => {
                                const mapObj = ar.reduce((acc, e) => {
                                acc.has(e) ? acc.set(e, true) : acc.set(e, false)
                                return acc
                                }, new Map())

                                return function(hasDup = true) {
                                if(hasDup) return [...mapObj.keys()]
                                else return [...mapObj].filter(([key, val]) => !val).map(([k, v])=> k)
                                }
                                }

                                const getArr = build(arr)

                                console.log(getArr())
                                console.log(getArr(false))








                                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                const build = ar => {
                                const mapObj = ar.reduce((acc, e) => {
                                acc.has(e) ? acc.set(e, true) : acc.set(e, false)
                                return acc
                                }, new Map())

                                return function(hasDup = true) {
                                if(hasDup) return [...mapObj.keys()]
                                else return [...mapObj].filter(([key, val]) => !val).map(([k, v])=> k)
                                }
                                }

                                const getArr = build(arr)

                                console.log(getArr())
                                console.log(getArr(false))





                                let arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                const build = ar => {
                                const mapObj = ar.reduce((acc, e) => {
                                acc.has(e) ? acc.set(e, true) : acc.set(e, false)
                                return acc
                                }, new Map())

                                return function(hasDup = true) {
                                if(hasDup) return [...mapObj.keys()]
                                else return [...mapObj].filter(([key, val]) => !val).map(([k, v])=> k)
                                }
                                }

                                const getArr = build(arr)

                                console.log(getArr())
                                console.log(getArr(false))






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 20 at 7:30









                                birdbird

                                997620




                                997620























                                    4














                                    As many other have said, the first one is just [...new Set(arr)]



                                    For the second, just filter out those that occur more than once:




                                    const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                    const count = (arr, e) => arr.filter(n => n == e).length

                                    const unique = arr => arr.filter(e => count(arr, e) < 2)

                                    console.log(unique(arr));








                                    share|improve this answer




























                                      4














                                      As many other have said, the first one is just [...new Set(arr)]



                                      For the second, just filter out those that occur more than once:




                                      const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                      const count = (arr, e) => arr.filter(n => n == e).length

                                      const unique = arr => arr.filter(e => count(arr, e) < 2)

                                      console.log(unique(arr));








                                      share|improve this answer


























                                        4












                                        4








                                        4







                                        As many other have said, the first one is just [...new Set(arr)]



                                        For the second, just filter out those that occur more than once:




                                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                        const count = (arr, e) => arr.filter(n => n == e).length

                                        const unique = arr => arr.filter(e => count(arr, e) < 2)

                                        console.log(unique(arr));








                                        share|improve this answer













                                        As many other have said, the first one is just [...new Set(arr)]



                                        For the second, just filter out those that occur more than once:




                                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                        const count = (arr, e) => arr.filter(n => n == e).length

                                        const unique = arr => arr.filter(e => count(arr, e) < 2)

                                        console.log(unique(arr));








                                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                        const count = (arr, e) => arr.filter(n => n == e).length

                                        const unique = arr => arr.filter(e => count(arr, e) < 2)

                                        console.log(unique(arr));





                                        const arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];

                                        const count = (arr, e) => arr.filter(n => n == e).length

                                        const unique = arr => arr.filter(e => count(arr, e) < 2)

                                        console.log(unique(arr));






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Mar 20 at 11:37









                                        JollyJokerJollyJoker

                                        21115




                                        21115























                                            2

















                                            var arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                                            var map = {};
                                            var finalResult = ;
                                            for (var i = 0; i < arr.length; i++) {
                                            if (!map.hasOwnProperty(arr[i])) {
                                            map[arr[i]] = true;
                                            finalResult.push(arr[i]);
                                            }
                                            }

                                            //if you need it sorted otherwise it will be in order
                                            finalResult.sort(function(a, b) {
                                            return a - b
                                            });

                                            console.log(finalResult);








                                            share|improve this answer






























                                              2

















                                              var arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                                              var map = {};
                                              var finalResult = ;
                                              for (var i = 0; i < arr.length; i++) {
                                              if (!map.hasOwnProperty(arr[i])) {
                                              map[arr[i]] = true;
                                              finalResult.push(arr[i]);
                                              }
                                              }

                                              //if you need it sorted otherwise it will be in order
                                              finalResult.sort(function(a, b) {
                                              return a - b
                                              });

                                              console.log(finalResult);








                                              share|improve this answer




























                                                2












                                                2








                                                2










                                                var arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                                                var map = {};
                                                var finalResult = ;
                                                for (var i = 0; i < arr.length; i++) {
                                                if (!map.hasOwnProperty(arr[i])) {
                                                map[arr[i]] = true;
                                                finalResult.push(arr[i]);
                                                }
                                                }

                                                //if you need it sorted otherwise it will be in order
                                                finalResult.sort(function(a, b) {
                                                return a - b
                                                });

                                                console.log(finalResult);








                                                share|improve this answer


















                                                var arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                                                var map = {};
                                                var finalResult = ;
                                                for (var i = 0; i < arr.length; i++) {
                                                if (!map.hasOwnProperty(arr[i])) {
                                                map[arr[i]] = true;
                                                finalResult.push(arr[i]);
                                                }
                                                }

                                                //if you need it sorted otherwise it will be in order
                                                finalResult.sort(function(a, b) {
                                                return a - b
                                                });

                                                console.log(finalResult);








                                                var arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                                                var map = {};
                                                var finalResult = ;
                                                for (var i = 0; i < arr.length; i++) {
                                                if (!map.hasOwnProperty(arr[i])) {
                                                map[arr[i]] = true;
                                                finalResult.push(arr[i]);
                                                }
                                                }

                                                //if you need it sorted otherwise it will be in order
                                                finalResult.sort(function(a, b) {
                                                return a - b
                                                });

                                                console.log(finalResult);





                                                var arr = [1, 2, 4, 2, 3, 3, 4, 5, 5, 5, 8, 8, 9, 10];
                                                var map = {};
                                                var finalResult = ;
                                                for (var i = 0; i < arr.length; i++) {
                                                if (!map.hasOwnProperty(arr[i])) {
                                                map[arr[i]] = true;
                                                finalResult.push(arr[i]);
                                                }
                                                }

                                                //if you need it sorted otherwise it will be in order
                                                finalResult.sort(function(a, b) {
                                                return a - b
                                                });

                                                console.log(finalResult);






                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited 2 days ago









                                                demo

                                                2,38433984




                                                2,38433984










                                                answered Mar 20 at 13:54









                                                JanspeedJanspeed

                                                1,3381315




                                                1,3381315















                                                    Popular posts from this blog

                                                    Bruad Bilen | Luke uk diar | NawigatsjuunCommonskategorii: BruadCommonskategorii: RunstükenWikiquote: Bruad

                                                    What is the offset in a seaplane's hull?

                                                    Slayer Innehåll Historia | Stil, komposition och lyrik | Bandets betydelse och framgångar | Sidoprojekt och samarbeten | Kontroverser | Medlemmar | Utmärkelser och nomineringar | Turnéer och festivaler | Diskografi | Referenser | Externa länkar | Navigeringsmenywww.slayer.net”Metal Massacre vol. 1””Metal Massacre vol. 3””Metal Massacre Volume III””Show No Mercy””Haunting the Chapel””Live Undead””Hell Awaits””Reign in Blood””Reign in Blood””Gold & Platinum – Reign in Blood””Golden Gods Awards Winners”originalet”Kerrang! Hall Of Fame””Slayer Looks Back On 37-Year Career In New Video Series: Part Two””South of Heaven””Gold & Platinum – South of Heaven””Seasons in the Abyss””Gold & Platinum - Seasons in the Abyss””Divine Intervention””Divine Intervention - Release group by Slayer””Gold & Platinum - Divine Intervention””Live Intrusion””Undisputed Attitude””Abolish Government/Superficial Love””Release “Slatanic Slaughter: A Tribute to Slayer” by Various Artists””Diabolus in Musica””Soundtrack to the Apocalypse””God Hates Us All””Systematic - Relationships””War at the Warfield””Gold & Platinum - War at the Warfield””Soundtrack to the Apocalypse””Gold & Platinum - Still Reigning””Metallica, Slayer, Iron Mauden Among Winners At Metal Hammer Awards””Eternal Pyre””Eternal Pyre - Slayer release group””Eternal Pyre””Metal Storm Awards 2006””Kerrang! Hall Of Fame””Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Bullet-For My Valentine booed at Metal Hammer Golden Gods Awards””Unholy Aliance””The End Of Slayer?””Slayer: We Could Thrash Out Two More Albums If We're Fast Enough...””'The Unholy Alliance: Chapter III' UK Dates Added”originalet”Megadeth And Slayer To Co-Headline 'Canadian Carnage' Trek”originalet”World Painted Blood””Release “World Painted Blood” by Slayer””Metallica Heading To Cinemas””Slayer, Megadeth To Join Forces For 'European Carnage' Tour - Dec. 18, 2010”originalet”Slayer's Hanneman Contracts Acute Infection; Band To Bring In Guest Guitarist””Cannibal Corpse's Pat O'Brien Will Step In As Slayer's Guest Guitarist”originalet”Slayer’s Jeff Hanneman Dead at 49””Dave Lombardo Says He Made Only $67,000 In 2011 While Touring With Slayer””Slayer: We Do Not Agree With Dave Lombardo's Substance Or Timeline Of Events””Slayer Welcomes Drummer Paul Bostaph Back To The Fold””Slayer Hope to Unveil Never-Before-Heard Jeff Hanneman Material on Next Album””Slayer Debut New Song 'Implode' During Surprise Golden Gods Appearance””Release group Repentless by Slayer””Repentless - Slayer - Credits””Slayer””Metal Storm Awards 2015””Slayer - to release comic book "Repentless #1"””Slayer To Release 'Repentless' 6.66" Vinyl Box Set””BREAKING NEWS: Slayer Announce Farewell Tour””Slayer Recruit Lamb of God, Anthrax, Behemoth + Testament for Final Tour””Slayer lägger ner efter 37 år””Slayer Announces Second North American Leg Of 'Final' Tour””Final World Tour””Slayer Announces Final European Tour With Lamb of God, Anthrax And Obituary””Slayer To Tour Europe With Lamb of God, Anthrax And Obituary””Slayer To Play 'Last French Show Ever' At Next Year's Hellfst””Slayer's Final World Tour Will Extend Into 2019””Death Angel's Rob Cavestany On Slayer's 'Farewell' Tour: 'Some Of Us Could See This Coming'””Testament Has No Plans To Retire Anytime Soon, Says Chuck Billy””Anthrax's Scott Ian On Slayer's 'Farewell' Tour Plans: 'I Was Surprised And I Wasn't Surprised'””Slayer””Slayer's Morbid Schlock””Review/Rock; For Slayer, the Mania Is the Message””Slayer - Biography””Slayer - Reign In Blood”originalet”Dave Lombardo””An exclusive oral history of Slayer”originalet”Exclusive! Interview With Slayer Guitarist Jeff Hanneman”originalet”Thinking Out Loud: Slayer's Kerry King on hair metal, Satan and being polite””Slayer Lyrics””Slayer - Biography””Most influential artists for extreme metal music””Slayer - Reign in Blood””Slayer guitarist Jeff Hanneman dies aged 49””Slatanic Slaughter: A Tribute to Slayer””Gateway to Hell: A Tribute to Slayer””Covered In Blood””Slayer: The Origins of Thrash in San Francisco, CA.””Why They Rule - #6 Slayer”originalet”Guitar World's 100 Greatest Heavy Metal Guitarists Of All Time”originalet”The fans have spoken: Slayer comes out on top in readers' polls”originalet”Tribute to Jeff Hanneman (1964-2013)””Lamb Of God Frontman: We Sound Like A Slayer Rip-Off””BEHEMOTH Frontman Pays Tribute To SLAYER's JEFF HANNEMAN””Slayer, Hatebreed Doing Double Duty On This Year's Ozzfest””System of a Down””Lacuna Coil’s Andrea Ferro Talks Influences, Skateboarding, Band Origins + More””Slayer - Reign in Blood””Into The Lungs of Hell””Slayer rules - en utställning om fans””Slayer and Their Fans Slashed Through a No-Holds-Barred Night at Gas Monkey””Home””Slayer””Gold & Platinum - The Big 4 Live from Sofia, Bulgaria””Exclusive! Interview With Slayer Guitarist Kerry King””2008-02-23: Wiltern, Los Angeles, CA, USA””Slayer's Kerry King To Perform With Megadeth Tonight! - Oct. 21, 2010”originalet”Dave Lombardo - Biography”Slayer Case DismissedArkiveradUltimate Classic Rock: Slayer guitarist Jeff Hanneman dead at 49.”Slayer: "We could never do any thing like Some Kind Of Monster..."””Cannibal Corpse'S Pat O'Brien Will Step In As Slayer'S Guest Guitarist | The Official Slayer Site”originalet”Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Kerrang! Awards 2006 Blog: Kerrang! Hall Of Fame””Kerrang! Awards 2013: Kerrang! Legend”originalet”Metallica, Slayer, Iron Maien Among Winners At Metal Hammer Awards””Metal Hammer Golden Gods Awards””Bullet For My Valentine Booed At Metal Hammer Golden Gods Awards””Metal Storm Awards 2006””Metal Storm Awards 2015””Slayer's Concert History””Slayer - Relationships””Slayer - Releases”Slayers officiella webbplatsSlayer på MusicBrainzOfficiell webbplatsSlayerSlayerr1373445760000 0001 1540 47353068615-5086262726cb13906545x(data)6033143kn20030215029