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

@ -181,7 +181,7 @@ try {
for (const tag of tags) {
const capitalizedTag = capitalize(tag, true);
// ![advanced](/advanced.svg)
if (capitalizedTag == 'Uncategorized') {
if (capitalizedTag === 'Uncategorized') {
uncategorizedOutput += `---\n ## _${capitalizedTag}_\n`;
for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) {
uncategorizedOutput += `\n${snippets[taggedSnippet[0] + '.md'] +

View File

@ -156,7 +156,7 @@ try {
for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1][0]))]
.filter(v => v)
.sort((a, b) => a.localeCompare(b))) {
if (capitalize(tag, true) == 'Uncategorized') {
if (capitalize(tag, true) === 'Uncategorized') {
uncategorizedOutput += md
.render(`## ${capitalize(tag, true)}\n`)
.replace(/<h2>/g, '<h2 style="text-align:center;">');

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]
```

View File

@ -5,7 +5,7 @@ Applies the Collatz algorithm.
If `n` is even, return `n/2`. Otherwise, return `3n+1`.
```js
const collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
```
```js

View File

@ -1,2 +1,2 @@
const collatz = n => (n % 2 == 0 ? n / 2 : 3 * n + 1);
const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
module.exports = collatz;

View File

@ -11,7 +11,7 @@ test('Testing collatz', (t) => {
let n = 9;
while(true){
if (n == 1){
if (n === 1){
t.pass('Eventually reaches 1');
break;
}

View File

@ -1,5 +1,5 @@
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), []);
module.exports = flatten;

View File

@ -1,6 +1,6 @@
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;
};
module.exports = isPrime;

View File

@ -1,9 +1,9 @@
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,
''
);
module.exports = join;

View File

@ -5,7 +5,7 @@ test('Testing negate', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof negate === 'function', 'negate is a Function');
t.deepEqual([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 == 0)), [1, 3, 5], "Negates a predicate function");
t.deepEqual([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)), [1, 3, 5], "Negates a predicate function");
//t.deepEqual(negate(args..), 'Expected');
//t.equal(negate(args..), 'Expected');
//t.false(negate(args..), 'Expected');

View File

@ -2,7 +2,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;
};
module.exports = primes;

View File

@ -5,7 +5,7 @@ test('Testing remove', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof remove === 'function', 'remove is a Function');
t.deepEqual(remove([1, 2, 3, 4], n => n % 2 == 0), [2, 4], "Removes elements from an array for which the given function returns false");
t.deepEqual(remove([1, 2, 3, 4], n => n % 2 === 0), [2, 4], "Removes elements from an array for which the given function returns false");
//t.deepEqual(remove(args..), 'Expected');
//t.equal(remove(args..), 'Expected');
//t.false(remove(args..), 'Expected');

View File

@ -1,4 +1,4 @@
Test log for: Sun Feb 04 2018 17:37:55 GMT+0200 (GTB Standard Time)
Test log for: Sun Feb 04 2018 17:47:43 GMT+0200 (GTB Standard Time)
> 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
> tape test/**/*.test.js | tap-spec
@ -1711,6 +1711,6 @@ Test log for: Sun Feb 04 2018 17:37:55 GMT+0200 (GTB Standard Time)
total: 813
passing: 813
duration: 2.5s
duration: 2.4s