mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-26 06:22:14 +00:00
Merge pull request #314 from fitzgen/Array.prototype.filter
Array.prototype.filter
This commit is contained in:
commit
947dfbeae0
@ -77,7 +77,7 @@ extern {
|
|||||||
#[wasm_bindgen(method, js_name = copyWithin)]
|
#[wasm_bindgen(method, js_name = copyWithin)]
|
||||||
pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
|
pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
|
||||||
|
|
||||||
///The concat() method is used to merge two or more arrays. This method
|
/// The concat() method is used to merge two or more arrays. This method
|
||||||
/// does not change the existing arrays, but instead returns a new array.
|
/// does not change the existing arrays, but instead returns a new array.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
|
||||||
@ -91,6 +91,13 @@ extern {
|
|||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn fill(this: &Array, value: JsValue, start: u32, end: u32) -> Array;
|
pub fn fill(this: &Array, value: JsValue, start: u32, end: u32) -> Array;
|
||||||
|
|
||||||
|
/// The `filter()` method creates a new array with all elements that pass the
|
||||||
|
/// test implemented by the provided function.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn filter(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> Array;
|
||||||
|
|
||||||
/// The length property of an object which is an instance of type Array
|
/// The length property of an object which is an instance of type Array
|
||||||
/// sets or returns the number of elements in that array. The value is an
|
/// sets or returns the number of elements in that array. The value is an
|
||||||
/// unsigned, 32-bit integer that is always numerically greater than the
|
/// unsigned, 32-bit integer that is always numerically greater than the
|
||||||
|
@ -2,6 +2,39 @@
|
|||||||
|
|
||||||
use project;
|
use project;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn filter() {
|
||||||
|
project()
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn keep_numbers(array: &js::Array) -> js::Array {
|
||||||
|
array.filter(&mut |x, _, _| x.as_f64().is_some())
|
||||||
|
}
|
||||||
|
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let characters = ["a", "c", "x", "n"];
|
||||||
|
let numbers = [1, 2, 3, 4];
|
||||||
|
let mixed = ["a", 1, "b", 2];
|
||||||
|
|
||||||
|
assert.deepStrictEqual(wasm.keep_numbers(characters), []);
|
||||||
|
assert.deepStrictEqual(wasm.keep_numbers(numbers), numbers);
|
||||||
|
assert.deepStrictEqual(wasm.keep_numbers(mixed), [1, 2]);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn index_of() {
|
fn index_of() {
|
||||||
project()
|
project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user