task02
by anatooly
HTML
'use strict';
// Написать функцию, которая принимает набор чисел, а возвращает минимальное из них
function funcName(args) {
}
Например:
funcName([78,56,232,12,8]),8,'Should return the smallest int 8');
funcName([78,56,232,12,18]),12,'Should return the smallest int 12');
funcName([78,56,232,412,228]),56,'Should return the smallest int 56');
funcName([78,56,232,12,0]),0,'Should return the smallest int 0');
funcName([1,56,232,12,8]),1,'Should return the smallest int 1');
// Solutions:
JavaScript
function funcName(args) {
let isArrayNumbers = true;
args.forEach(function(num) {
if (typeof num !== 'number') {
isArrayNumbers = false;
return null;
}
});
if (isArrayNumbers) {
return args.sort((a, b) => a - b)[0];
} else {
return null;
}
}
console.log(
funcName([78,56,232,12,8]), // 8,'Should return the smallest int 8');
funcName([78,56,232,12,18]), // 12,'Should return the smallest int 12');
funcName([78,56,232,412,228]), // 56,'Should return the smallest int 56');
funcName([78,56,232,12,0]), // 0,'Should return the smallest int 0');
funcName([1,56,232,12,8]) // 1,'Should return the smallest int 1');
);