3テラバイト

プログラム関連備忘録サイト。主にゲーム。

JavaScript

JavaScriptでMath.jsを用いて階乗の計算をする

投稿日:

math.permutations関数の引数に任意の数値を渡すと、その階乗の値が返されます。
また、第二引数にサブセットの値を渡すと、そこまでの計算結果が返されます。

<html>
  <head>
    <script type=text/javascript src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/9.4.4/math.min.js"></script>
  </head>
  <body>
    <script>
      var ret1 = math.permutations(6);
      console.log(ret1);

      var ret2 = math.permutations(6, 3);
      console.log(ret2);
    </script>
  </body>
</html>

リンク

math.js | an extensive math library for JavaScript and Node.js
https://mathjs.org/docs/reference/functions/permutations.html

-JavaScript


comment

メールアドレスが公開されることはありません。

関連記事

no image

File APIでinput要素で選択したファイルの情報を確認する

サンプル <input type="file"> <script> const input = document.querySelector(‘input’ …

no image

シンプルなレスポンシブチャートJavaScriptライブラリChartist.jsの使い方

公式サイト http://gionkunz.github.io/chartist-js/index.html GETTING STARTEDhttp://gionkunz.github.io/char …

no image

チャートを簡単に追加できるJavaScriptライブラリChart.jsの使い方

折れ線グラフ、棒グラフ、レーダーチャート、ドーナツチャート、円グラフ、ポーラチャート、バブルチャート、散布図等のチャートをWebサイトに簡単に追加することができます。 公式サイト https://ww …

no image

JavaScriptでブラウザ履歴の前のページや次のページへ移動する

前のページへ window.history.back() 次のページへ window.history.forward() 指定ページ数前へ window.history.go関数の引数にマイナスの数値 …

no image

JavaScriptで位置座標を取得する

navigator.geolocation.getCurrentPosition関数で取得できます。 引数には成功時、失敗時のコールバック関数と、オプションを渡します。 <html> &l …