Skip to content

Commit 506f7f7

Browse files
committed
list contains
1 parent eb2c54d commit 506f7f7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/lib/Toolbox/Toolbox.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<block type="lists_get" />
104104
<block type="lists_index" />
105105
<block type="lists_length" />
106+
<block type="lists_contains" />
106107
<sep gap="48"></sep>
107108
<block type="lists_set" />
108109
<block type="lists_join" />

src/resources/blocks/lists.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function register() {
8585
}
8686
],
8787
inputsInline: true,
88-
output: null,
88+
output: "Number",
8989
colour: categoryColor,
9090
}, (block) => {
9191
const VALUE = javascriptGenerator.valueToCode(block, 'VALUE')
@@ -94,6 +94,32 @@ function register() {
9494
return [`${code}`, 0];
9595
})
9696

97+
registerBlock(`${categoryPrefix}contains`, {
98+
message0: '%1 contains %2',
99+
args0: [
100+
{
101+
"type": "input_value",
102+
"name": "INPUT",
103+
"check": "List"
104+
},
105+
{
106+
"type": "field_input",
107+
"name": "VALUE",
108+
"check": null,
109+
"value": "",
110+
"acceptsBlocks": true
111+
},
112+
],
113+
inputsInline: true,
114+
output: "Boolean",
115+
colour: categoryColor,
116+
}, (block) => {
117+
const VALUE = javascriptGenerator.valueToCode(block, 'VALUE')
118+
const INPUT = javascriptGenerator.valueToCode(block, 'INPUT')
119+
const code = `(${INPUT}.includes(${VALUE}))`;
120+
return [`${code}`, 0];
121+
})
122+
97123
registerBlock(`${categoryPrefix}set`, {
98124
message0: 'set item %1 of %2 to %3',
99125
args0: [

0 commit comments

Comments
 (0)