Filter the number
Tue Oct 04 2022 09:55:03 GMT+0000 (Coordinated Universal Time)
Saved by
@j_jivan
#javascript
/*Description:
Filter the number
Oh, no! The number has been mixed up with the text. Your goal is to retrieve the number from the text, can you return the number back to its original state?
Task
Your task is to return a number from a string.
Details
You will be given a string of numbers and letters mixed up, you have to return all the numbers in that string in the order they occur.
*/
var FilterString = function (value) {
let numberStr = "";
for (let i = 0; i < value.length; ++i) {
if (!isNaN(Number(value[i]))) {
numberStr+= value[i];
}
}
return Number(numberStr);
};
content_copyCOPY
https://www.codewars.com/kata/55b051fac50a3292a9000025/train/javascript
Comments