Who can help to explain this JavaScript algorithm [].filter.call()

前端 未结 7 995
情深已故
情深已故 2021-01-22 03:41

I have task to receive unique element in order from string as parameter. I do not understand how this function uniqueElements returns [\'A\',\'B\',\'C\',\'B\']

7条回答
  •  盖世英雄少女心
    2021-01-22 04:04

    var word = "AAAABBBBCCBB";
    var unique = word.split('').filter(function(item, i, ar) {
      return ar.indexOf(item) === i;
    }).join('');

提交回复
热议问题