-5

I was ask a question in an interview to convert a string number to a number. eg : My string is "TEN" . and I have to convert it to number 10.

Please help.

Thanks

2 Answers2

4

if (string === "TEN") value = 10;

s4l4x
  • 148
  • 6
  • 1
    This is it, the problem's been solved. We can all go home now. – Raphael Serota Dec 18 '14 at 19:42
  • Actually , they mentioned that think of it as you have a file that contains hundred thousand strings . If I go by If else statements. It will not be an efficient method. – tweety_03 Dec 18 '14 at 21:04
0

I think you misunderstood the interviewer's question. He meant getting the number that is currently in a string, not getting the number that is currently spelled out in a string.

But this has already been answered: https://stackoverflow.com/a/4090577/2725684

Community
  • 1
  • 1
Waxi
  • 1,641
  • 2
  • 14
  • 20