А
Size: a a a
А
А
S
function calculateGuests (string) {
const match = string.match(/\d+/)
if (match) {
const number = Number(match[0])
if (number > 0) {
return number
}
}
return 'not a number'
}
Д
Д
S
y
function calculateGuests (string) {
const match = string.match(/\d+/)
if (match) {
const number = Number(match[0])
if (number > 0) {
return number
}
}
return 'not a number'
}
const getGuests = str => {
const match = str.match(/\d+/g);
const notNumber = 'not a number';
if(match){
return match.reduce((acc, x) => {
const n = +x || 0;
if(n > acc) {
acc = n;
}
return acc;
}, 0) || notNumber;
}
return notNumber;
}
console.log(
getGuests('I think 5 guests') === 5,
getGuests('Big company of 15 dudes') === 15,
getGuests('5') === 5,
getGuests('alone') === 'not a number',
getGuests('0') === 'not a number'
);
j
j
Д
y
S
const getGuests = str => {
const match = str.match(/\d+/g);
const notNumber = 'not a number';
if(match){
return match.reduce((acc, x) => {
const n = +x || 0;
if(n > acc) {
acc = n;
}
return acc;
}, 0) || notNumber;
}
return notNumber;
}
console.log(
getGuests('I think 5 guests') === 5,
getGuests('Big company of 15 dudes') === 15,
getGuests('5') === 5,
getGuests('alone') === 'not a number',
getGuests('0') === 'not a number'
);
y
function calculateGuests (string) {
const match = string.match(/\d+/)
if (match) {
const number = Number(match[0])
if (number > 0) {
return number
}
}
return 'not a number'
}
calculateGuests('Нас будет примерно 5 либо 7 но всего человек должно быть 10')= 5
S
calculateGuests('Нас будет примерно 5 либо 7 но всего человек должно быть 10')= 5
y
S
calculateGuests('Нас будет примерно 5 либо 7 но всего человек должно быть 10')= 5
y
S
ei
calculateGuests('Нас будет примерно 5 либо 7 но всего человек должно быть 10')= 5
y