Help us understand the problem. What is going on with this article?

2次元配列中の重複削除

Google Spreadsheet使ってると2次元配列中の複数の要素にまたがった重複削除とかやりたくなると思いますが,こうすると行数短く書けるなぁと思いついたのでメモ.

remove_duplicated.js
const A = [["田中", "裕也"], ["田中", "智史"], ["吉田", "智史"], ["田中", "智史"]];

const unique_A = A.filter(function(e, index){
  return !A.some(function(e2, index2){
    return index > index2 && e[0] == e2[0] && e[1] == e2[1];
  });
});

Logger.log(unique_A); // 田中,裕也,田中,智史,吉田,智史

配列から重複削除するには他にSetやreduce使う方法があるらしいけど,そっちはまだ試してない.

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away