Add a block to reverse a list (#844)

This commit is contained in:
Tim Dawborn
2017-01-22 05:48:42 +11:00
committed by Andrew n marshall
parent f6168e1364
commit 46316c7cea
12 changed files with 240 additions and 1 deletions

View File

@@ -392,3 +392,11 @@ Blockly.JavaScript['lists_split'] = function(block) {
var code = input + '.' + functionName + '(' + delimiter + ')';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};
Blockly.JavaScript['lists_reverse'] = function(block) {
// Block for reversing a list.
var list = Blockly.JavaScript.valueToCode(block, 'LIST',
Blockly.JavaScript.ORDER_FUNCTION_CALL) || '[]';
var code = list + '.slice().reverse()';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};