Fixed error prone checking etc in codebase

This commit is contained in:
Angelos Chalaris
2018-02-04 17:48:07 +02:00
parent 89f572efbc
commit c6c49ab567
18 changed files with 25 additions and 25 deletions

View File

@ -9,7 +9,7 @@ Omit the second argument, `depth` to flatten only to a depth of `1` (single flat
```js
const flatten = (arr, depth = 1) =>
depth != 1
depth !== 1
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
: arr.reduce((a, v) => a.concat(v), []);
```

View File

@ -8,7 +8,7 @@ Return `false` if any of them divides the given number, else return `true`, unle
```js
const isPrime = num => {
const boundary = Math.floor(Math.sqrt(num));
for (var i = 2; i <= boundary; i++) if (num % i == 0) return false;
for (var i = 2; i <= boundary; i++) if (num % i === 0) return false;
return num >= 2;
};
```

View File

@ -10,9 +10,9 @@ Omit the third argument, `end`, to use the same value as `separator` by default.
const join = (arr, separator = ',', end = separator) =>
arr.reduce(
(acc, val, i) =>
i == arr.length - 2
i === arr.length - 2
? acc + val + end
: i == arr.length - 1 ? acc + val : acc + val + separator,
: i === arr.length - 1 ? acc + val : acc + val + separator,
''
);
```

View File

@ -9,5 +9,5 @@ const negate = func => (...args) => !func(...args);
```
```js
[1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 == 0)); // [ 1, 3, 5 ]
[1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)); // [ 1, 3, 5 ]
```

View File

@ -9,7 +9,7 @@ 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)));
numsTillSqroot.forEach(x => (arr = arr.filter(y => y % x !== 0 || y === x)));
return arr;
};
```

View File

@ -16,5 +16,5 @@ const remove = (arr, func) =>
```
```js
remove([1, 2, 3, 4], n => n % 2 == 0); // [2, 4]
remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4]
```