Skip to content

Commit

Permalink
doc test for find_index
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Ceccato authored and Angelo Ceccato committed Feb 17, 2024
1 parent e4de0e7 commit 703411b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion core/engine/src/object/builtins/jstypedarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,42 @@ impl JsTypedArray {
)
}

/// Calls `TypedArray.prototype.findIndex()`.
/// The `find_index` method of Array instances returns the index of the first
/// element in an array that satisfies the provided testing function.
/// If no elements satisfy the testing function, None is returned.
///
/// It calls `TypedArray.prototype.findIndex()`.
///
/// # Examples
///
/// ```
/// # use boa_engine::{JsResult, object::{builtins::JsUint8Array, FunctionObjectBuilder}, NativeFunction, JsValue, Context};
/// # fn main() -> JsResult<()> {
/// let context = &mut Context::default();
/// let data: Vec<u8> = (0..=255).collect();
/// let array = JsUint8Array::from_iter(data, context)?;
///
/// let greter_than_10_predicate = FunctionObjectBuilder::new(
/// context.realm(),
/// NativeFunction::from_fn_ptr(|_this, args, _context| {
/// let element = args
/// .first()
/// .cloned()
/// .unwrap_or_default()
/// .as_number()
/// .expect("error at number conversion");
/// Ok(JsValue::Boolean(element > 10.0))
/// }),
/// )
/// .build();
/// assert_eq!(
/// array.find_index(greter_than_10_predicate, None, context),
/// Ok(Some(11))
/// );
///
/// # Ok(())
/// # }
/// ```
#[inline]
pub fn find_index(
&self,
Expand Down

0 comments on commit 703411b

Please sign in to comment.