Skip to content

Commit d5079e9

Browse files
fixing multinames
Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
1 parent 19e4437 commit d5079e9

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

pages/ai.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ export default function AI({ readings }) {
2525
everything listed below. I will read anything and everything, and this is
2626
just a list. Please send me more things to read! :)`;
2727

28+
function createNameList(names) {
29+
let name = "";
30+
31+
if (names.length == 1) {
32+
return `${names[0].firstName} ${names[0].lastName}`
33+
}
34+
35+
for (let i = 0; i < names.length; i++) {
36+
if (i == names.length - 1) {
37+
name += `and ${names[i].firstName} ${names[i].lastName}`
38+
39+
return name;
40+
}
41+
name += `${names[i].firstName} ${names[i].lastName}, `
42+
}
43+
44+
return name;
45+
}
46+
2847
return (
2948
<>
3049
<NextSeo
@@ -49,13 +68,7 @@ export default function AI({ readings }) {
4968
<h2>{reading.title}</h2>
5069
</Link>
5170

52-
<div>
53-
{reading.author.map((author, index) => (
54-
<h4 key={index} className={styles.info}>
55-
{author.firstName} {author.lastName}
56-
</h4>
57-
))}
58-
</div>
71+
<p className={styles.info}> {createNameList(reading.author)}</p>
5972
<h4 className={styles.info}>{reading.date}</h4>
6073
</div>
6174
))}

0 commit comments

Comments
 (0)