-
-
Save alexxstst/a2bc05a98a068d6498e1 to your computer and use it in GitHub Desktop.
VK API: Parse json Args to array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* For check: https://vk.com/dev/execute | |
*/ | |
// var itemList = Args.list; | |
// var listSeparator = Args.listSeparator; | |
// var asInteger = Args.asInteger; | |
var itemList = "123456,789012,345678,901234,567890"; | |
var listSeparator = ","; | |
var asInteger = 1; | |
var result = []; | |
var charsLength = itemList.length; | |
var currentPosition = 0; | |
var previousSeparatorPosition = -1; | |
var item; | |
while (currentPosition < charsLength) { | |
if (itemList.substr(currentPosition, 1) == listSeparator) { | |
item = itemList.substr(previousSeparatorPosition + 1, currentPosition - previousSeparatorPosition - 1); | |
if (asInteger == 1) | |
item = parseInt(item); | |
result.push(item); | |
previousSeparatorPosition = currentPosition; | |
} | |
currentPosition = currentPosition + 1; | |
} | |
if (previousSeparatorPosition < currentPosition) { | |
item = itemList.substr(previousSeparatorPosition + 1, currentPosition - previousSeparatorPosition - 1); | |
if (asInteger == 1) | |
item = parseInt(item); | |
result.push(item); | |
} | |
return result; | |
if (previousSeparatorPosition < currentPosition) | |
result.push(Args.list.substr(previousSeparatorPosition + 1, currentPosition - previousSeparatorPosition - 1)); | |
return result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment