5 kyu

WinH's Kata #2 - JavaScript Array-Parser

104 of 110WinH

Description:

Task: Your task is to implement parseArray function that parses the array representation to JS-Array.

Examples:

"[1,2,3,4]" -> [1,2,3,4]
" [1.5, 2, 3, [1, 2, 3, [4]], 5]" -> [1.5, 2, 3, [1, 2, 3, [4]], 5]
"[1,2,3,4]" -> Just (A [ N 1, N 2, N 3, N 4 ])
" [1.5, 2, 3, [1, 2, 3, [4]], 5]" -> Just (A [ N 1.5, N 2, N 3, A [ N 1, N 2, N 3, A [ N 4 ] ], N 5 ])

In case of parse error return null or Nothing:

"abc" -> null
"1" -> null
"[1,2,3" -> null
"[#]" -> null
"abc" -> Nothing
"1" -> Nothing
"[1,2,3" -> Nothing
"[#]" -> Nothing

For simplicity, only number literals appear in the array:

"[0xFF, 1e2]" -> Just (A [ N 255, N 100 ])

Note: require() / eval() / JSON.parse() / new Function() are disabled.

Data Structures
Algorithms

More By Author:

Check out these other kata created by WinH

Stats:

CreatedJan 28, 2016
PublishedJan 28, 2016
Warriors Trained439
Total Skips22
Total Code Submissions1398
Total Times Completed110
JavaScript Completions104
Haskell Completions7
Total Stars17
% of votes with a positive feedback rating92% of 39
Total "Very Satisfied" Votes34
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes1
Total Rank Assessments7
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • WinH Avatar
  • myjinxin2015 Avatar
  • JohanWiltink Avatar
  • Omiant Avatar
  • trashy_incel Avatar
Ad