Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (3)
exo 1 avec max et moyenne
· 6e162cbf
Herbert Caffarel
authored
Jan 06, 2025
6e162cbf
exo stats objets avec affectation de fonctions existantes
· fb18e21d
Herbert Caffarel
authored
Jan 06, 2025
fb18e21d
exo stats avec objets indépendant
· 60388a7b
Herbert Caffarel
authored
Jan 06, 2025
60388a7b
Show whitespace changes
Inline
Side-by-side
exo01-stats/stat.js
View file @
60388a7b
function
min
()
{
const
stats
=
{
min
:
function
min
()
{
if
(
arguments
.
length
==
0
)
{
return
NaN
;
}
...
...
@@ -11,8 +12,37 @@ function min() {
}
}
return
minimum
;
},
max
:
function
max
()
{
if
(
arguments
.
length
==
0
)
{
return
NaN
;
}
console
.
log
(
min
(
5
,
3
,
-
8
,
1
,
25
,
12
));
console
.
log
(
min
());
let
maximum
=
-
Infinity
;
// Parcourir toutes les valeurs de arguments
for
(
let
value
of
arguments
)
{
// Si valeur < minimum, alors minimum <- valeur
if
(
value
>
maximum
)
{
maximum
=
value
;
}
}
return
maximum
;
},
moyenne
:
function
moyenne
()
{
if
(
arguments
.
length
==
0
)
{
return
NaN
;
}
let
accu
=
0
;
// un accumulateur de sommes
// Parcourir toutes les valeurs de arguments
for
(
let
value
of
arguments
)
{
accu
+=
value
;
// On cumule les valeurs
}
return
accu
/
arguments
.
length
;
}
}
console
.
log
(
stats
.
min
(
5
,
3
,
-
8
,
1
,
25
,
12
));
console
.
log
(
stats
.
min
());
console
.
log
(
stats
.
max
(
5
,
3
,
-
8
,
1
,
25
,
12
));
console
.
log
(
stats
.
max
());
console
.
log
(
stats
.
moyenne
(
5
,
3
,
-
8
,
1
,
25
,
12
));
console
.
log
(
stats
.
moyenne
());