Array.prototype.map() expects a return value from arrow function
29
30routes.map((allRoutes) => {
31 Object.keys(allRoutes).map((index) => {
32 allRoutes[index].map((route) => {33 fastify.route(route);
34 })
35 })
Array.prototype.map() expects a return value from arrow function
28const routes = require('./Routes')
29
30routes.map((allRoutes) => {
31 Object.keys(allRoutes).map((index) => {32 allRoutes[index].map((route) => {
33 fastify.route(route);
34 })
Array.prototype.map() expects a return value from arrow function
27
28const routes = require('./Routes')
29
30routes.map((allRoutes) => {31 Object.keys(allRoutes).map((index) => {
32 allRoutes[index].map((route) => {
33 fastify.route(route);
Description
Array
has several methods for filtering, mapping, and folding.
If we forget to write return statement in a callback of those, it's probably a mistake.
If you don't want to use a return
or don't need the returned results, consider using .forEach
instead.
Bad Practice
const indexMap = myArray.reduce(function(memo, item, index) {
memo[item] = index;
}, {});
const foo = Array.from(nodes, function(node) {
if (node.tagName === "DIV") {
return true;
}
});
const bar = foo.filter(function(x) {
if (x) {
return true;
} else {
return;
}
});
Recommended
const indexMap = myArray.reduce(function(memo, item, index) {
memo[item] = index;
return memo;
}, {});
const foo = Array.from(nodes, function(node) {
if (node.tagName === "DIV") {
return true;
}
return false;
});
const bar = foo.map(node => node.getAttribute("id"));