Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
8
test/primes/primes.js
Normal file
8
test/primes/primes.js
Normal file
@ -0,0 +1,8 @@
|
||||
const primes = num => {
|
||||
let arr = Array.from({ length: num - 1 }).map((x, i) => i + 2),
|
||||
sqroot = Math.floor(Math.sqrt(num)),
|
||||
numsTillSqroot = Array.from({ length: sqroot - 1 }).map((x, i) => i + 2);
|
||||
numsTillSqroot.forEach(x => (arr = arr.filter(y => y % x !== 0 || y === x)));
|
||||
return arr;
|
||||
};
|
||||
module.exports = primes;
|
||||
9
test/primes/primes.test.js
Normal file
9
test/primes/primes.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const primes = require('./primes.js');
|
||||
|
||||
|
||||
test('primes is a Function', () => {
|
||||
expect(primes).toBeInstanceOf(Function);
|
||||
});
|
||||
t.deepEqual(primes(10), [2, 3, 5, 7], "Generates primes up to a given number, using the Sieve of Eratosthenes.");
|
||||
|
||||
Reference in New Issue
Block a user