39 lines
904 B
JavaScript
39 lines
904 B
JavaScript
|
|
||
|
function getNumberFromName(name) {
|
||
|
|
||
|
name = name + ' '
|
||
|
|
||
|
let number = name.split('')
|
||
|
|
||
|
let newNumber = ''
|
||
|
let list = []
|
||
|
|
||
|
for (let i = 0; i < number.length; i++) {
|
||
|
|
||
|
if (!isNaN(Number(number[i])) && number[i].trim().length > 0) {
|
||
|
newNumber += number[i]
|
||
|
}
|
||
|
else {
|
||
|
if (!isNaN(Number(newNumber)) && newNumber.trim().length > 0) {
|
||
|
list.push(newNumber)
|
||
|
}
|
||
|
newNumber = ''
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// longestString = list.filter(str => str.length === Math.max(...list.map(s => s.length)))[0];
|
||
|
|
||
|
// console.log('list: ', list)
|
||
|
|
||
|
|
||
|
let longestString = ""; // variable to store the longest string
|
||
|
for (let i = 0; i < list.length; i++) {
|
||
|
if (list[i].length > longestString.length) {
|
||
|
longestString = list[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return longestString
|
||
|
}
|
||
|
|
||
|
module.exports = getNumberFromName;
|