Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CWG - pages
//JavaScript-C24.2.0 (SpiderMonkey) print("Hello, world!") var headingsInput = "_id,_subject,_topic,_optionalImagekeyPage1,_gridPage1,_gridAnswersPage1"; var valuesInput = "CWG00001,,,LTRS0022,LTRS0006*0|LTRS0007*1|LTRS0008*1|LTRS0009*1|LTRS0010*1|LTRS0019*1|LTRS0020*1|LTRS0021*1|LTRS0022*1,LTRS0020*LTRS0021*LTRS0022,LTRS0022,LTRS0006*0|LTRS0007*1|LTRS0008*1|LTRS0009*1|LTRS0010*1|LTRS0019*1|LTRS0020*1|LTRS0021*1|LTRS0022*1,LTRS0020*LTRS0021*LTRS0022"; function ComposeWordsGrid(headingsInput, valuesInput) { // Utilities.sleep(1000); var json = {}; if(valuesInput !== undefined && headingsInput !== undefined) { var headingsArray = headingsInput.toString().split(","); var valuesArray = valuesInput.toString().split(","); json[headingsArray[0]] = valuesArray[0]; json[headingsArray[1]] = valuesArray[1]; json[headingsArray[2]] = valuesArray[2]; var _gridPages = []; var temp = 0; var pagesCount = (valuesArray.length - 3) / 3; for(var i = 0; i <= pagesCount - 1; i++) { print("loop : "+i) print("") var _gridPage = {}; _gridPage["_optionalImagekey"] = valuesArray[3 + (i * 3)]; // -- 2 var input = valuesArray[4 + (i * 3)].toString().split("|"); if(input[0] === "") continue; var _gridCells = []; for(var j = 0; j < input.length; j++) { var _gridCell = {}; var subInput = input[j].toString().split("*"); _gridCell["_gridValue"] = subInput[0]; _gridCell["_gridValueType"] = parseInt(subInput[1]); _gridCells.push(_gridCell); } _gridPage["_gridCells"] = _gridCells; //---- _gridPages.push(_gridPage); //--- 3 var input1 = valuesArray[5 + (i * 3)].toString().split("*"); var _gridCellsAnswers = []; for(var k = 0; k < input1.length; k++) _gridCellsAnswers.push(input1[k]); _gridPage["_gridCellsAnswers"] = _gridCellsAnswers; //--- } json["_gridPages"] = _gridPages; var finalObj = {}; finalObj[valuesArray[0]] = json; } return JSON.stringify(finalObj); } print(ComposeWordsGrid(headingsInput, valuesInput));
run
|
edit
|
history
|
help
0
Javascript reverse string, one index
playing with undefined variables
class Node
H
Alternating Sign Fibonacci
ECMAScript5 - js
новинка
Iterate the iteratable object from the iterator object
Javascript Basics If statements
Triangle