isPrime = (x) -> return false if x < 2 return true if x == 2 return false if x % 2 == 0 for i in [3..(Math.sqrt x)] by 2 return false if x % i == 0 true for i in [1..100] console.log (if isPrime i then 'JOJO!' else i) Register as a new user and use Qiita more conveniently You get articles that match your needsYou can efficiently read back useful informationYou can use dark themeWhat you can do wit
![素数のときにJoJo - CoffeeScript - - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/e4cf297a1435f19fbc0a5a0cac6429426e0a03c7/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-9f5428127621718a910c8b63951390ad.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTkxNiZoPTMzNiZ0eHQ9JUU3JUI0JUEwJUU2JTk1JUIwJUUzJTgxJUFFJUUzJTgxJUE4JUUzJTgxJThEJUUzJTgxJUFCSm9KbyUyMC0lMjBDb2ZmZWVTY3JpcHQlMjAtJTIwJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmdHh0LWNsaXA9ZWxsaXBzaXMmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz1hYzI2YjNhY2M1MWRjOTAzYmU3MGVhMjY0Y2MzOWVhOA%26mark-x%3D142%26mark-y%3D112%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTYxNiZ0eHQ9JTQwa2FfJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9MzYmdHh0LWFsaWduPWxlZnQlMkN0b3Amcz03NTFlZmU4ZjZjMTcwMWRlODJmZDUwMDlhNTMwMmU0OQ%26blend-x%3D142%26blend-y%3D491%26blend-mode%3Dnormal%26s%3D59c4fbffabe6cf1905a9c448bac8ad04)