peak-finding

1.0.3 • Public • Published

node-peak-finding Build Status Coverage Status devDependency Status Code Climate

Find an element in an array where the element peaks.

In the One-Dimensional version an element is a peak if this element is larger or equal to both the elements on its sides.

In the Two-Dimensional version an element is a peak if this element is larger or equal to all the elements on its sides (North, south, west and east sides).

Install

$ npm install --save peak-finding

Usage

var peakFinding = require('peak-finding');
 
peakFinding([1, 3, 4, 3, 5, 1, 3]);
//=> 4
 
peakFinding([[23, 20, 19, 10],
             [14, 10, 12, 11],
             [15,  9, 11, 21],
             [16, 11, 10, 17]]);
//=> 23

Time complexity

1D Version: Θ(log2(n)), where n is the length of the input list.

2D Version: Θ(n * log2(m)) or Θ(n * log2(n)) if n = m, where n is the number of columns and m the number of rows.

API

peakFinding(list)

list

Required
Type: Array

License

MIT © Vinícius do Carmo

Package Sidebar

Install

npm i peak-finding

Weekly Downloads

0

Version

1.0.3

License

MIT

Last publish

Collaborators

  • vinimdocarmo