File tree 2 files changed +41
-1
lines changed 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ extern {
77
77
#[ wasm_bindgen( method, js_name = copyWithin) ]
78
78
pub fn copy_within ( this : & Array , target : i32 , start : i32 , end : i32 ) -> Array ;
79
79
80
- ///The concat() method is used to merge two or more arrays. This method
80
+ /// The concat() method is used to merge two or more arrays. This method
81
81
/// does not change the existing arrays, but instead returns a new array.
82
82
///
83
83
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
@@ -91,6 +91,13 @@ extern {
91
91
#[ wasm_bindgen( method) ]
92
92
pub fn fill ( this : & Array , value : JsValue , start : u32 , end : u32 ) -> Array ;
93
93
94
+ /// The `filter()` method creates a new array with all elements that pass the
95
+ /// test implemented by the provided function.
96
+ ///
97
+ /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
98
+ #[ wasm_bindgen( method) ]
99
+ pub fn filter ( this : & Array , predicate : & mut FnMut ( JsValue , u32 , Array ) -> bool ) -> Array ;
100
+
94
101
/// The length property of an object which is an instance of type Array
95
102
/// sets or returns the number of elements in that array. The value is an
96
103
/// unsigned, 32-bit integer that is always numerically greater than the
Original file line number Diff line number Diff line change 2
2
3
3
use project;
4
4
5
+ #[ test]
6
+ fn filter ( ) {
7
+ project ( )
8
+ . file ( "src/lib.rs" , r#"
9
+ #![feature(proc_macro, wasm_custom_section)]
10
+
11
+ extern crate wasm_bindgen;
12
+ use wasm_bindgen::prelude::*;
13
+ use wasm_bindgen::js;
14
+
15
+ #[wasm_bindgen]
16
+ pub fn keep_numbers(array: &js::Array) -> js::Array {
17
+ array.filter(&mut |x, _, _| x.as_f64().is_some())
18
+ }
19
+
20
+ "# )
21
+ . file ( "test.ts" , r#"
22
+ import * as assert from "assert";
23
+ import * as wasm from "./out";
24
+
25
+ export function test() {
26
+ let characters = ["a", "c", "x", "n"];
27
+ let numbers = [1, 2, 3, 4];
28
+ let mixed = ["a", 1, "b", 2];
29
+
30
+ assert.deepStrictEqual(wasm.keep_numbers(characters), []);
31
+ assert.deepStrictEqual(wasm.keep_numbers(numbers), numbers);
32
+ assert.deepStrictEqual(wasm.keep_numbers(mixed), [1, 2]);
33
+ }
34
+ "# )
35
+ . test ( )
36
+ }
37
+
5
38
#[ test]
6
39
fn index_of ( ) {
7
40
project ( )
You can’t perform that action at this time.
0 commit comments