-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fabi0o solution #3
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Viking } from "../types/viking"; | ||
import styles from "../styles/VikingCard.module.css"; | ||
const VikingCard = ({ viking }: { viking: Viking }) => { | ||
return ( | ||
<div className={styles.card}> | ||
<div className={styles.cardFullName}>{viking.fullName}</div> | ||
<div className={styles.cardAge}>Age: {viking.age}</div> | ||
<div className={styles.cardHomeTown}>Town: {viking.hometown}</div> | ||
<div className={styles.cardChildren}> | ||
{viking.presenceOfChildren ? "Has children" : "Childless"} | ||
</div> | ||
<div> | ||
Fight with | ||
{viking.canFightWithSword | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I am not a huge fan of chaining ternary operators that way. |
||
? " Sword" | ||
: viking.canFightWithAxe | ||
? " Axe" | ||
: viking.canFightWithSpear | ||
? " Spear" | ||
: " Hammer"} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default VikingCard; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Viking } from "../types/viking"; | ||
type vikingDataJSON = { | ||
fullName: string; | ||
village: string; | ||
age: number; | ||
valkyrie: string; | ||
hasSon: boolean; | ||
}; | ||
type vikingDataYaml = { | ||
name: string; | ||
weapon: "sword" | "spear" | "axe" | "hammer"; | ||
name_of_father: string; | ||
has_home_in: string; | ||
years_old: number; | ||
number_of_children: number; | ||
}; | ||
|
||
export const handleVikingList = ( | ||
vikingsJSON: Array<vikingDataJSON>, | ||
vikingsYaml: Array<vikingDataYaml> | ||
) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could write return type here (: Viking[]) and then you could remove all those Array from inside the function and it would work. You don't have to use type assertion everywhere for every variable, Typescript is clever enough to infer that :) |
||
const jsonVikingList: Array<Viking> = vikingsJSON.map((vikingJSON) => { | ||
const fullViking = { | ||
fullName: vikingJSON.fullName, | ||
presenceOfChildren: vikingJSON.hasSon ? true : false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't have to return true or false from ternary operator, as the condition is already a boolean. |
||
age: vikingJSON.age, | ||
hometown: vikingJSON.village, | ||
canFightWithSword: vikingsJSON.indexOf(vikingJSON) <= 2 ? true : false, | ||
canFightWithAxe: vikingsJSON.indexOf(vikingJSON) < 6 ? true : false, | ||
canFightWithSpear: vikingsJSON.indexOf(vikingJSON) >= 6 ? true : false, | ||
}; | ||
return fullViking; | ||
}); | ||
const yamlVikingList: Array<Viking> = vikingsYaml.map((vikingYaml) => { | ||
const fullViking = { | ||
fullName: `${vikingYaml.name} ${vikingYaml.name_of_father}sson`, | ||
presenceOfChildren: vikingYaml.number_of_children > 0 ? true : false, | ||
age: vikingYaml.years_old, | ||
hometown: vikingYaml.has_home_in, | ||
canFightWithSword: vikingYaml.weapon == "sword" ? true : false, | ||
canFightWithAxe: vikingYaml.weapon == "axe" ? true : false, | ||
canFightWithSpear: vikingYaml.weapon == "spear" ? true : false, | ||
}; | ||
return fullViking; | ||
}); | ||
const fullVikingList: Array<Viking> = [...jsonVikingList, ...yamlVikingList]; | ||
const vikingList: Array<Viking> = fullVikingList.filter( | ||
(viking) => viking.age > 25 && viking.age < 65 | ||
); | ||
return vikingList; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const withYAML = require("next-yaml"); | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
swcMinify: true, | ||
} | ||
|
||
module.exports = nextConfig | ||
}; | ||
module.exports = nextConfig; | ||
module.exports = withYAML(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You replaced our custom next config with that function, so we lost it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lack of whitespace in all places. The code is hard to read as there is too few "enters" used. It applies to all your code, not only this file :)