LoginSignup
4
1

More than 5 years have passed since last update.

JavaScript素数判定のプログラムを作ってみた

Last updated at Posted at 2018-05-08

関数型で素数を判定するプログラムを書いてみたがあっているのだろうか??
もっといい方法があれば教えて欲しいです。


//開始値
const start = 2
//終了値
const end = 100

//数値の生成
let range = function(min,max){
    return [...Array(max - min + 1).keys()].map(x => x + min)
}
range(start, end).filter( i => {
    const s = Math.round(Math.sqrt(i))
    return range(2,s).every(j => {
        return i % j != 0 
    })
}).forEach( i => {console.log(i)})

4
1
4

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
4
1