LoginSignup
0
0

More than 3 years have passed since last update.

P5.js 日本語リファレンス(sort)

Last updated at Posted at 2020-05-24

このページでは「P5.js 日本語リファレンス」 の sort関数を説明します。

sort()

説明文

注意: 非推奨

sort() は非推奨であり、p5の将来のバージョンで削除される予定です。代わりにarray.sort() を使用してください。

数値の配列を最小から最大にソートするか、単語の配列をアルファベット順に並べます。元の配列は変更されません。並べ替えられた配列が返されます。 countパラメータはソートする要素の数を示します。たとえば、配列に12個の要素があり count が5に設定されている場合、配列の最初の5個の要素のみが並べ替えられます。

構文

sort(list, [count])

パラメタ

  • list

    Array:並べ替える配列

  • count

    Number:並べ替える要素の数。先頭0から並べ替えます(オプション)

戻り値

Array:ソートされたリスト

例1

function setup()  {
  let numbers = [2, 6, 1, 5, 14, 9, 8, 12];
  print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12]
  let count = 5; // 配列の長さより短い値を指定

  numbers = sort(numbers, count);
  print(numbers); // [1,2,5,6,14,9,8,12]
}

例2

function setup() {
  let words = ['banana',  'apple',  'pear',  'lime'];
  print(words); // ['banana',  'apple',  'pear',  'lime']
  let count = 4; //配列の長さ

  words = sort(words, count);
  print(words); // ['apple',  'banana',  'lime',  'pear']
}

著作権

p5.js was created by Lauren McCarthy and is developed by a community of collaborators, with support from the Processing Foundation and NYU ITP. Identity and graphic design by Jerel Johnson.

ライセンス

Creative Commons(CC BY-NC-SA 4.0) に従います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0