async function getPosts(user_id, amount);
async function getComments(user_id, amount);
...
async function getInitialData(user_id) {
const [
posts,
comments,
...
] = Promise.all([
getPosts(user_id, 20),
getComments(user_id, 100),
...
]);
return {
posts: posts,
comments: comments,
...
}
}
const validateCred = number => {
let numberReverse = number.reverse();
let evenArray = []; // even numbers
let oddArray = []; // odd numbers
for (let index = 0; index < numberReverse.length; index += 2) {
oddArray.push(numberReverse[index]);
}
for (let indexEven = 1; indexEven < numberReverse.length; indexEven += 2) {
evenArray.push(numberReverse[indexEven] * 2);
for (let indexMinus = 0; indexMinus < evenArray.length; indexMinus++) {
if (evenArray[indexMinus] >= 10) {
evenArray[indexMinus] -= 9;
}
}
}
let totalArray = oddArray.concat(evenArray);
let final = totalArray.reduce(function(a, b) {
return a + b;
});
return final;
};
batch = [
[1,2,3],
[4,5,6],
[4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]
]
const findInvalidCards = batchArray => {
for (let i = 0; i < batchArray.length; i++) {
console.log( `Array: ${ JSON.stringify(batchArray[i]) }, result: ${ validateCred(batchArray[i]) }` );
}
};
findInvalidCards(batch)