Skip to content
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

done :) #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

.prettierrc
35 changes: 35 additions & 0 deletions lib/vikings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {Viking,VikingJson,VikingYaml} from "../types/vikingTypes"

function JsonToViking(vikingJson: VikingJson[]){
return vikingJson.map((el)=>{
return{
fullName: el.fullName,
hometown: el.village,
age: el.age,
presenceOfChildren: el.hasSon
}
})
}

function YamlToViking(vikingYaml: VikingYaml[]){
return vikingYaml.map((el)=>{
return{
fullName: el.name,
hometown: el.has_home_in,
age: el.years_old,
presenceOfChildren: el.number_of_children > 0 ? true : false,
canFightWithSword: el.weapon === "sword" ? true : false,
canFightWithSpear: el.weapon === "spear" ? true : false,
canFightWithAxe: el.weapon === "axe" ? true : false
}
})
}


export default function getVikings(vikingsJson: VikingJson[], vikingsYaml: VikingYaml[]){
const vikingsFromJson = JsonToViking(vikingsJson) as Viking[]
const vikingsFromYaml = YamlToViking(vikingsYaml) as Viking[]

return [...vikingsFromJson, ...vikingsFromYaml].filter(el => el.age >= 25 && el.age <=65)

}
4 changes: 4 additions & 0 deletions module.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.yaml" {
const data: { [key: string]: any };
export default data;
}
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}
const nextYaml = require("next-yaml")

module.exports = nextConfig
module.exports = nextYaml
Loading