split

How to split() a string to an array of integers

北慕城南 提交于 2020-12-25 00:32:44
问题 I have a string that should be executed as an array: var q = "The, 1, 2, Fox, Jumped, 3, Over, 4"; var z = q.split(','); If I use split() , it will create an array of strings: [‘The’, '1', '2', ‘Fox’, ‘Jumped’, '3', ‘Over’, '4'] and I don’t need that. I need an array like: [‘The’, 1, 2, ‘Fox’, ‘Jumped’, 3, ‘Over’, 4] indicating which is a string and which is a number. 回答1: One option is using the Number constructor which returns a number or NaN : var res = q.split(',').map(el => { let n =

How to split() a string to an array of integers

大憨熊 提交于 2020-12-25 00:31:38
问题 I have a string that should be executed as an array: var q = "The, 1, 2, Fox, Jumped, 3, Over, 4"; var z = q.split(','); If I use split() , it will create an array of strings: [‘The’, '1', '2', ‘Fox’, ‘Jumped’, '3', ‘Over’, '4'] and I don’t need that. I need an array like: [‘The’, 1, 2, ‘Fox’, ‘Jumped’, 3, ‘Over’, 4] indicating which is a string and which is a number. 回答1: One option is using the Number constructor which returns a number or NaN : var res = q.split(',').map(el => { let n =

What is the best way to split a string by a delimiter functionally?

假装没事ソ 提交于 2020-12-24 08:12:49
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter

What is the best way to split a string by a delimiter functionally?

…衆ロ難τιáo~ 提交于 2020-12-24 08:11:34
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter

What is the best way to split a string by a delimiter functionally?

倾然丶 夕夏残阳落幕 提交于 2020-12-24 08:10:22
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter

What is the best way to split a string by a delimiter functionally?

不问归期 提交于 2020-12-24 08:10:16
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter

What is the best way to split a string by a delimiter functionally?

大憨熊 提交于 2020-12-24 08:08:22
问题 I tried to write the program in Haskell that will take a string of integer numbers delimitated by comma, convert it to list of integer numbers and increment each number by 1. For example "1,2,-5,-23,15" -> [2,3,-4,-22,16] Below is the resulting program import Data.List main :: IO () main = do n <- return 1 putStrLn . show . map (+1) . map toInt . splitByDelimiter delimiter $ getList n getList :: Int -> String getList n = foldr (++) [] . intersperse [delimiter] $ replicate n inputStr delimiter

Split a list into half by even and odd indexes? [duplicate]

可紊 提交于 2020-12-22 01:41:51
问题 This question already has answers here : How to split an iterable into two lists with alternating elements (4 answers) Closed last month . Possible Duplicate: Python program to split a list into two lists with alternating elements I have a list like this: list1 = [blah, 3, haha, 2, pointer, 1, poop, fire] The output I want is: list = [3, 2, 1, fire] So what I want is to make a list of even elements of the former list. I tried using a for statement and tried to delete 2nth element while

Split a list into half by even and odd indexes? [duplicate]

左心房为你撑大大i 提交于 2020-12-22 01:32:33
问题 This question already has answers here : How to split an iterable into two lists with alternating elements (4 answers) Closed last month . Possible Duplicate: Python program to split a list into two lists with alternating elements I have a list like this: list1 = [blah, 3, haha, 2, pointer, 1, poop, fire] The output I want is: list = [3, 2, 1, fire] So what I want is to make a list of even elements of the former list. I tried using a for statement and tried to delete 2nth element while

Split a list into half by even and odd indexes? [duplicate]

笑着哭i 提交于 2020-12-22 01:29:34
问题 This question already has answers here : How to split an iterable into two lists with alternating elements (4 answers) Closed last month . Possible Duplicate: Python program to split a list into two lists with alternating elements I have a list like this: list1 = [blah, 3, haha, 2, pointer, 1, poop, fire] The output I want is: list = [3, 2, 1, fire] So what I want is to make a list of even elements of the former list. I tried using a for statement and tried to delete 2nth element while