Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
1
1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yihao Zuo
1
Commits
15dcba34
Commit
15dcba34
authored
2 years ago
by
Yihao Zuo
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
6e104fdc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
_22113800_.js
+217
-0
217 additions, 0 deletions
_22113800_.js
with
217 additions
and
0 deletions
_22113800_.js
0 → 100644
+
217
−
0
View file @
15dcba34
const
fs
=
require
(
'
fs
'
);
module
.
exports
=
{
// Exercise 1 - Iris Species Classifier
exercise1
:
(
SepalLen
,
SepalWid
,
PetalLen
,
PetalWid
)
=>
{
if
(
PetalLen
<
2.5
){
return
'
setosa
'
;}
else
if
(
PetalWid
<
1.8
){
if
(
PetalLen
<
5
)
{
if
(
PetalLen
<
1.7
)
{
return
'
versicolor
'
;
}
else
{
return
'
virginica
'
;
}
}
else
if
(
PetalWid
>=
1.6
)
{
if
(
SepalLen
<
7
)
{
return
'
versicolor
'
;
}
else
{
return
'
virginica
'
;
}
}
else
{
return
'
virginica
'
}}
else
if
(
PetalLen
<
4.9
)
{
if
(
SepalLen
<
6
)
{
return
'
versicolor
'
;
}
else
{
return
'
virginica
'
;
}
}
else
{
return
'
virginica
'
;}
},
// Exercise 2 - Dog Breeds Standards
exercise2
:
(
breed
,
height
,
weight
,
male
)
=>
{
// Create an object that stores the standard height and standard weight of different types of dogs
var
standards
=
{
"
Balldog
"
:
{
"
male
"
:
{
"
height
"
:
15
,
"
weight
"
:
50
},
"
female
"
:
{
"
height
"
:
14
,
"
weight
"
:
40
}
},
"
Dalmatian
"
:
{
"
male
"
:
{
"
height
"
:
24
,
"
weight
"
:
70
},
"
female
"
:
{
"
height
"
:
19
,
"
weight
"
:
45
}
},
"
Maltese
"
:
{
"
male
"
:
{
"
height
"
:
9
,
"
weight
"
:
7
},
"
female
"
:
{
"
height
"
:
7
,
"
weight
"
:
6
}
}
}
// calculates whether the actual height and weight are between 90% and 110% of the standard values
if
(
breed
in
standards
)
{
var
Puppy_height
=
standards
[
breed
][
male
?
"
male
"
:
"
female
"
].
height
;
var
Puppy_weight
=
standards
[
breed
][
male
?
"
male
"
:
"
female
"
].
weight
;
if
((
0.9
*
Puppy_height
>
height
)
&&
(
height
>
1.1
*
Puppy_height
))
{
if
((
0.9
*
Puppy_weight
>
weight
)
&&
(
weight
>
1.1
*
Puppy_weight
))
{
return
false
;
}
return
true
;
}
return
true
;
}
else
{
return
false
;
}
},
// Exercise 3 - Basic Statistics
exercise3
:
(
l
)
=>
{
l
.
sort
();
/*creat var..*/
let
min
,
max
;
min
=
l
[
0
];
max
=
l
[
l
.
length
-
1
];
let
sum
=
0
for
(
let
i
=
0
;
i
<
l
.
length
;
i
++
)
{
sum
+=
l
[
i
];
}
let
aver
,
med
;
aver
=
sum
/
l
.
length
;
if
(
l
.
length
%
2
===
0
)
{
med
=
(
l
[
l
.
length
/
2
]
+
l
[
l
.
length
/
2
-
1
])
/
2
;
}
else
{
med
=
l
[
Math
.
floor
(
l
.
length
/
2
)];
}
let
List_1
;
List_1
=
[];
for
(
let
i
=
0
;
i
<
l
.
length
;
i
++
)
{
List_1
[
i
]
=
l
[
i
]
**
2
;
}
/*creat med^2,aver^2...*/
let
aver2
,
med2
,
min2
,
max2
,
sum2
;
min2
=
List_1
[
0
];
max2
=
List_1
[
List_1
.
length
-
1
];
sum2
=
0
for
(
let
i
=
0
;
i
<
List_1
.
length
;
i
++
)
{
sum2
+=
List_1
[
i
];
}
aver2
=
sum2
/
List_1
.
length
;
if
(
List_1
.
length
%
2
===
0
)
{
med2
=
(
List_1
[
List_1
.
length
/
2
]
+
List_1
[
List_1
.
length
/
2
-
1
])
/
2
;
}
else
{
med2
=
List_1
[
Math
.
floor
(
List_1
.
length
/
2
)];
}
return
([[
min
,
aver
,
med
,
max
],[
min2
,
aver2
,
med2
,
max2
]]);
},
// Exercise 4 - Finite-State Machine Simulator
exercise4
:
(
trans
,
init_state
,
input_list
)
=>
{
let
Li
=
[];
n
=
input_list
.
length
;
for
(
let
i
=
0
;
i
<
n
;
i
++
)
{
let
key
=
init_state
+
'
/
'
+
input_list
[
i
];
if
(
key
in
trans
)
{
let
n
=
trans
[
key
];
init_state
=
n
[
0
];
Li
.
push
(
n
.
slice
(
2
));
}
}
return
Li
;
},
// Exercise 5 - Document Stats
exercise5
:
(
filename
)
=>
{
return
undefined
;
},
// Exercise 6 - List Depth
exercise6
:
(
l
)
=>
{
function
maximum1
(
l
)
{
let
a
=
[]
for
(
let
i
=
0
;
i
<
l
.
length
;
i
++
)
{
/*Check whether there is an array in the array*/
if
(
l
[
i
]
instanceof
Array
)
{
a
.
push
(
maximum1
(
l
[
i
]))
}
}
if
(
a
.
length
>
0
)
{
/*Get the maximum value*/
return
1
+
Math
.
max
(...
a
)
}
return
1
;
}
return
maximum1
(
l
)
},
// Exercise 7 - Change, please
exercise7
:
(
amount
,
coins
)
=>
{
function
f
(
amount
,
coins
)
{
var
wallet
=
[
2
,
1
,
0.5
,
0.2
,
0.1
,
0.05
,
0.02
,
0.01
];
if
(
amount
===
0
&&
coins
===
0
)
{
return
true
;
}
else
{
for
(
var
x
of
wallet
)
{
if
(
amount
>=
x
)
{
if
((
amount
-
x
===
0
&&
coins
-
1
>
0
)
||
(
amount
-
x
>
0
&&
coins
-
1
===
0
))
{
continue
;
}
else
{
if
(
f
(
round
(
amount
-
x
,
2
),
coins
-
1
))
{
return
true
;
}
}
}
}
return
null
;
}
}
if
(
f
(
amount
,
coins
)
===
null
)
{
return
false
;
}
else
{
return
true
;
}
},
// Exercise 8 - Five Letter Unscramble
exercise8
:
(
s
)
=>
{
return
undefined
;
},
// Exercise 9 - Wordle Set
exercise9
:
(
green
,
yellow
,
gray
)
=>
{
return
undefined
;
},
// Exercise 10 - One Step of Wordle
exercise10
:
(
green
,
yellow
,
gray
)
=>
{
return
undefined
;
},
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment