LoginSignup
2
2

More than 5 years have passed since last update.

メソッドチェーンでconcat

Posted at

concatで再帰をかけてみた。返ってくるものは引数と同じ配列。
配列以外のものを引数にしたときの挙動は知らない。

function isort(x) {
  var n = x.length;
  if(n <= 1) return x;
  var x1 = x.shift(x);
  var x2 = x.shift(x);
  return [x1].concat([x2].concat(isort(x)));
}
console.log(isort([4,3,5,2,1]));
2
2
2

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
2
2