@@ -34,8 +34,18 @@ import copy = require( '@stdlib/array/base/copy' );
3434import copyIndexed = require( '@stdlib/array/base/copy-indexed' ) ;
3535import filled = require( '@stdlib/array/base/filled' ) ;
3636import filledBy = require( '@stdlib/array/base/filled-by' ) ;
37+ import flatten = require( '@stdlib/array/base/flatten' ) ;
38+ import flatten2d = require( '@stdlib/array/base/flatten2d' ) ;
39+ import flatten2dBy = require( '@stdlib/array/base/flatten2d-by' ) ;
40+ import flatten3d = require( '@stdlib/array/base/flatten3d' ) ;
41+ import flatten3dBy = require( '@stdlib/array/base/flatten3d-by' ) ;
42+ import flatten4d = require( '@stdlib/array/base/flatten4d' ) ;
43+ import flatten4dBy = require( '@stdlib/array/base/flatten4d-by' ) ;
44+ import flatten5d = require( '@stdlib/array/base/flatten5d' ) ;
45+ import flatten5dBy = require( '@stdlib/array/base/flatten5d-by' ) ;
3746import getter = require( '@stdlib/array/base/getter' ) ;
3847import incrspace = require( '@stdlib/array/base/incrspace' ) ;
48+ import last = require( '@stdlib/array/base/last' ) ;
3949import linspace = require( '@stdlib/array/base/linspace' ) ;
4050import logspace = require( '@stdlib/array/base/logspace' ) ;
4151import nCartesianProduct = require( '@stdlib/array/base/n-cartesian-product' ) ;
@@ -308,6 +318,278 @@ interface Namespace {
308318 */
309319 filledBy : typeof filledBy ;
310320
321+ /**
322+ * Flattens an n-dimensional nested array.
323+ *
324+ * ## Notes
325+ *
326+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
327+ *
328+ * @param x - input array
329+ * @param shape - array shape
330+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
331+ * @returns flattened array
332+ *
333+ * @example
334+ * var x = [ [ 1, 2 ], [ 3, 4 ] ];
335+ *
336+ * var out = ns.flatten( x, [ 2, 2 ], false );
337+ * // returns [ 1, 2, 3, 4 ]
338+ *
339+ * @example
340+ * var x = [ [ 1, 2 ], [ 3, 4 ] ];
341+ *
342+ * var out = ns.flatten( x, [ 2, 2 ], true );
343+ * // returns [ 1, 3, 2, 4 ]
344+ */
345+ flatten : typeof flatten ;
346+
347+ /**
348+ * Flattens a two-dimensional nested array.
349+ *
350+ * ## Notes
351+ *
352+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
353+ *
354+ * @param x - input array
355+ * @param shape - array shape
356+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
357+ * @returns flattened array
358+ *
359+ * @example
360+ * var x = [ [ 1, 2 ], [ 3, 4 ] ];
361+ *
362+ * var out = ns.flatten2d( x, [ 2, 2 ], false );
363+ * // returns [ 1, 2, 3, 4 ]
364+ *
365+ * @example
366+ * var x = [ [ 1, 2 ], [ 3, 4 ] ];
367+ *
368+ * var out = ns.flatten2d( x, [ 2, 2 ], true );
369+ * // returns [ 1, 3, 2, 4 ]
370+ */
371+ flatten2d : typeof flatten2d ;
372+
373+ /**
374+ * Flattens a two-dimensional nested array according to a callback function.
375+ *
376+ * ## Notes
377+ *
378+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
379+ *
380+ * @param x - input array
381+ * @param shape - array shape
382+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
383+ * @param clbk - callback function
384+ * @param thisArg - callback execution context
385+ * @returns flattened array
386+ *
387+ * @example
388+ * function scale( v ) {
389+ * return v * 2;
390+ * }
391+ *
392+ * var x = [ [ 1, 2 ], [ 3, 4 ] ];
393+ *
394+ * var out = ns.flatten2dBy( x, [ 2, 2 ], false, scale );
395+ * // returns [ 2, 4, 6, 8 ]
396+ *
397+ * @example
398+ * function scale( v ) {
399+ * return v * 2;
400+ * }
401+ *
402+ * var x = [ [ 1, 2 ], [ 3, 4 ] ];
403+ *
404+ * var out = ns.flatten2dBy( x, [ 2, 2 ], true, scale );
405+ * // returns [ 2, 6, 4, 8 ]
406+ */
407+ flatten2dBy : typeof flatten2dBy ;
408+
409+ /**
410+ * Flattens a three-dimensional nested array.
411+ *
412+ * ## Notes
413+ *
414+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
415+ *
416+ * @param x - input array
417+ * @param shape - array shape
418+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
419+ * @returns flattened array
420+ *
421+ * @example
422+ * var x = [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ];
423+ *
424+ * var out = ns.flatten3d( x, [ 2, 1, 2 ], false );
425+ * // returns [ 1, 2, 3, 4 ]
426+ *
427+ * @example
428+ * var x = [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ];
429+ *
430+ * var out = ns.flatten3d( x, [ 2, 1, 2 ], true );
431+ * // returns [ 1, 3, 2, 4 ]
432+ */
433+ flatten3d : typeof flatten3d ;
434+
435+ /**
436+ * Flattens a three-dimensional nested array according to a callback function.
437+ *
438+ * ## Notes
439+ *
440+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
441+ *
442+ * @param x - input array
443+ * @param shape - array shape
444+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
445+ * @param clbk - callback function
446+ * @param thisArg - callback execution context
447+ * @returns flattened array
448+ *
449+ * @example
450+ * var x = [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ];
451+ *
452+ * function scale( v ) {
453+ * return v * 2;
454+ * }
455+ *
456+ * var out = ns.flatten3dBy( x, [ 2, 1, 2 ], false, scale );
457+ * // returns [ 2, 4, 6, 8 ]
458+ *
459+ * @example
460+ * var x = [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ];
461+ *
462+ * function scale( v ) {
463+ * return v * 2;
464+ * }
465+ *
466+ * var out = ns.flatten3dBy( x, [ 2, 1, 2 ], true, scale );
467+ * // returns [ 2, 6, 4, 8 ]
468+ */
469+ flatten3dBy : typeof flatten3dBy ;
470+
471+ /**
472+ * Flattens a four-dimensional nested array.
473+ *
474+ * ## Notes
475+ *
476+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
477+ *
478+ * @param x - input array
479+ * @param shape - array shape
480+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
481+ * @returns flattened array
482+ *
483+ * @example
484+ * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ];
485+ *
486+ * var out = ns.flatten4d( x, [ 2, 1, 1, 2 ], false );
487+ * // returns [ 1, 2, 3, 4 ]
488+ *
489+ * @example
490+ * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ];
491+ *
492+ * var out = ns.flatten4d( x, [ 2, 1, 1, 2 ], true );
493+ * // returns [ 1, 3, 2, 4 ]
494+ */
495+ flatten4d : typeof flatten4d ;
496+
497+ /**
498+ * Flattens a four-dimensional nested array according to a callback function.
499+ *
500+ * ## Notes
501+ *
502+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
503+ *
504+ * @param x - input array
505+ * @param shape - array shape
506+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
507+ * @returns flattened array
508+ *
509+ * @example
510+ * function scale( v ) {
511+ * return v * 2;
512+ * }
513+ *
514+ * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ];
515+ *
516+ * var out = ns.flatten4dBy( x, [ 2, 1, 1, 2 ], false, scale );
517+ * // returns [ 2, 4, 6, 8 ]
518+ *
519+ * @example
520+ * function scale( v ) {
521+ * return v * 2;
522+ * }
523+ *
524+ * var x = [ [ [ [ 1, 2 ] ] ], [ [ [ 3, 4 ] ] ] ];
525+ *
526+ * var out = ns.flatten4dBy( x, [ 2, 1, 1, 2 ], true, scale );
527+ * // returns [ 2, 6, 4, 8 ]
528+ */
529+ flatten4dBy : typeof flatten4dBy ;
530+
531+ /**
532+ * Flattens a five-dimensional nested array.
533+ *
534+ * ## Notes
535+ *
536+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
537+ *
538+ * @param x - input array
539+ * @param shape - array shape
540+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
541+ * @returns flattened array
542+ *
543+ * @example
544+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
545+ *
546+ * var out = ns.flatten5d( x, [ 2, 1, 1, 1, 2 ], false );
547+ * // returns [ 1, 2, 3, 4 ]
548+ *
549+ * @example
550+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
551+ *
552+ * var out = ns.flatten5d( x, [ 2, 1, 1, 1, 2 ], true );
553+ * // returns [ 1, 3, 2, 4 ]
554+ */
555+ flatten5d : typeof flatten5d ;
556+
557+ /**
558+ * Flattens a five-dimensional nested array according to a callback function.
559+ *
560+ * ## Notes
561+ *
562+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
563+ *
564+ * @param x - input array
565+ * @param shape - array shape
566+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
567+ * @param clbk - callback function
568+ * @param thisArg - callback execution context
569+ * @returns flattened array
570+ *
571+ * @example
572+ * function scale( v ) {
573+ * return v * 2;
574+ * }
575+ *
576+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
577+ *
578+ * var out = ns.flatten5dBy( x, [ 2, 1, 1, 1, 2 ], false, scale );
579+ * // returns [ 1, 2, 3, 4 ]
580+ *
581+ * @example
582+ * function scale( v ) {
583+ * return v * 2;
584+ * }
585+ *
586+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
587+ *
588+ * var out = ns.flatten5dBy( x, [ 2, 1, 1, 1, 2 ], true, scale );
589+ * // returns [ 1, 3, 2, 4 ]
590+ */
591+ flatten5dBy : typeof flatten5dBy ;
592+
311593 /**
312594 * Returns an accessor function for retrieving an element from an indexed array-like object.
313595 *
@@ -339,6 +621,20 @@ interface Namespace {
339621 */
340622 incrspace : typeof incrspace ;
341623
624+ /**
625+ * Returns the last element of an array-like object.
626+ *
627+ * @param arr - input array
628+ * @returns last element
629+ *
630+ * @example
631+ * var arr = [ 1, 2, 3 ];
632+ *
633+ * var out = ns.last( x );
634+ * // returns 3
635+ */
636+ last : typeof last ;
637+
342638 /**
343639 * Generates a linearly spaced numeric array.
344640 *
0 commit comments