-7

I have an array of strings:

["5:17", "8:22", "3:34", "5:23", "7:12", "7:24", "6:46", "4:45", "4:40", "7:58", "11:51", "9:13", "5:50", "5:52", "5:49", "8:57", "11:29", "3:07", "5:59", "3:31"]

How can I convert the strings to numbers?

12
  • This look like a time in string, can you please tell your expected output? Commented Oct 20, 2018 at 14:43
  • 1
    What number are you expecting for a string like "5:17" ? Commented Oct 20, 2018 at 14:44
  • time without string =) Commented Oct 20, 2018 at 14:45
  • 1
    What i see is, it's time - 5:17 means 5 hours and 17 minutes, now when displaying in number format, either you can display in minutes or in hours. What are you expecting here? Commented Oct 20, 2018 at 14:47
  • 1
    Great!!! Then it will be a string as you can't denote colon ':' as a number :) Commented Oct 20, 2018 at 14:54

1 Answer 1

-1

You can use "map" as below

arr.map(d => {
    let [min, sec] = d.split(':')
    return +min * 60  + +sec
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.