Basic fetch example
by Kristian Jabilles
HTML
<div class="articles-list"></div>
JavaScript
function solution(A, K) {
// write your code in JavaScript (Node.js 8.9.4)
/* let count = 1;
let table = '';
let border = ''
let tableBorder = '';
const maxChar = Math.max(...A).toString().length;
for (i = 0; i < maxChar; i++) {
tableBorder += '-';
}
A.map((item, index) => {
const lineBreak = count === K ? '\n': '';
if(count > K) {
count = 1;
}
// table += maxChar;
//border += `+${tableBorder}${lineBreak}|${item.toString()}`;
//table += `|${item.toString()}${lineBreak}`;
table += `+${tableBorder}${lineBreak}`;
count++;
});
console.log(table) */
// console.log(border)
let table = ''
let count = 1;
let tableBorder = '';
const maxChar = Math.max(...A).toString().length;
for (i = 0; i < maxChar; i++) {
tableBorder += '-';
}
A.map(item => {
const lineBreak = count === K ? '\n': '';
if(count > K) {
count = 1;
}
table += `
+${tableBorder}+
|${item.toString()}
+${tableBorder}+
`;
count++;
});
console.log(table)
/* console.log(`
+-----+-----+-----+-----+-----+
| 4| 35| 80| 123| 44|
+-----+-----+-----+-----+-----+
| 8| 5|
+-----+-----+
`) */
}
solution([4, 35, 80, 123, 12345, 44, 8, 5], 5)