mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Merge pull request #660 from Kenny2github/patch-1
Add [string] contains [string] block
This commit is contained in:
commit
6988571eb8
2 changed files with 15 additions and 0 deletions
|
@ -30,6 +30,7 @@ class Scratch3OperatorsBlocks {
|
|||
operator_join: this.join,
|
||||
operator_letter_of: this.letterOf,
|
||||
operator_length: this.length,
|
||||
operator_contains: this.contains,
|
||||
operator_mod: this.mod,
|
||||
operator_round: this.round,
|
||||
operator_mathop: this.mathop
|
||||
|
@ -106,6 +107,13 @@ class Scratch3OperatorsBlocks {
|
|||
length (args) {
|
||||
return Cast.toString(args.STRING).length;
|
||||
}
|
||||
|
||||
contains (args) {
|
||||
const format = function (string) {
|
||||
return Cast.toString(string).toLowerCase();
|
||||
};
|
||||
return format(args.STRING1).includes(format(args.STRING2));
|
||||
}
|
||||
|
||||
mod (args) {
|
||||
const n = Cast.toNumber(args.NUM1);
|
||||
|
|
|
@ -141,6 +141,13 @@ test('length', t => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('contains', t => {
|
||||
t.strictEqual(blocks.contains({STRING1: 'hello world', STRING2: 'hello'}), true);
|
||||
t.strictEqual(blocks.contains({STRING1: 'foo', STRING2: 'bar'}), false);
|
||||
t.strictEqual(blocks.contains({STRING1: 'HeLLo world', STRING2: 'hello'}), true);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('mod', t => {
|
||||
t.strictEqual(blocks.mod({NUM1: 1, NUM2: 1}), 0);
|
||||
t.strictEqual(blocks.mod({NUM1: 3, NUM2: 6}), 3);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue