This repository has been archived by the owner on Nov 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35b33dd
commit e1e72d3
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# even-index | ||
Returns an array with items evenly indexed | ||
|
||
![npm](https://img.shields.io/npm/v/even-index.svg) ![license](https://img.shields.io/npm/l/even-index.svg) ![github-issues](https://img.shields.io/github/issues/Prosen-Ghosh/even-index.svg) | ||
|
||
|
||
![travis-status](https://img.shields.io/travis/Prosen-Ghosh/even-index.svg) | ||
![stars](https://img.shields.io/github/stars/Prosen-Ghosh/even-index.svg) | ||
![forks](https://img.shields.io/github/forks/Prosen-Ghosh/even-index.svg) | ||
|
||
## Features | ||
|
||
|
||
## `npm` Install | ||
|
||
`npm install --save even-index` | ||
|
||
|
||
## Script Tag | ||
|
||
#### For Development | ||
```js | ||
<script src=""></script> | ||
``` | ||
#### For Production | ||
```js | ||
<script src=""></script> | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
|
||
const evenIndex = require('even-index'); | ||
|
||
evenIndex([]); | ||
//=> [] | ||
|
||
evenIndex([1]); | ||
//=> [ 1 ] | ||
|
||
evenIndex([1,-10]); | ||
//=> [ 1 ] | ||
|
||
evenIndex([1,-10,45]); | ||
//=> [ 1, 45 ] | ||
|
||
evenIndex(["foo","baz","bar","bob","tim"]); | ||
//=> [ 'foo', 'bar', 'tim' ] | ||
|
||
evenIndex(["foo","baz","bar",{a : 10},[10,20,30]]); | ||
//=> [ 'foo', 'bar', [ 10, 20, 30 ] ] | ||
|
||
evenIndex(["foo","baz","bar",[10,30],function(){}]); | ||
//=> [ 'foo', 'bar', [Function] ] | ||
|
||
evenIndex(); // without parameter this function will return a type error | ||
//=> TypeError: expect an array got undefined | ||
|
||
evenIndex({}); // this function only expect an array | ||
//=> TypeError: expect an array got object | ||
|
||
``` | ||
|
||
## Author | ||
|
||
Prosen Ghosh <[email protected]> (https://bd.linkedin.com/in/prosen-ghosh-baba9aa8) | ||
|
||
## License | ||
|
||
- **MIT** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const evenIndex = (function(){ | ||
'use strict'; | ||
const fn = function(arr){ | ||
if(Object.prototype.toString.call(arr).toLowerCase() !== '[object array]')throw new TypeError('expect an array got ' + typeof arr); | ||
return arr.reduce((p,c,i) => { | ||
if(!(i&1))p.push(c); | ||
return p; | ||
},[]); | ||
} | ||
return fn; | ||
})(); | ||
|
||
if (typeof module === 'object' && module.exports) { | ||
module.exports = evenIndex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "even-index", | ||
"version": "1.0.0", | ||
"description": "Returns an array with items evenly indexed", | ||
"main": "even-index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"readme": "node ./node_modules/.bin/node-readme" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Prosen-Ghosh/even-index.git" | ||
}, | ||
"keywords": [ | ||
"even", | ||
"number", | ||
"array", | ||
"index", | ||
"elements" | ||
], | ||
"author": "Prosen Ghosh <[email protected]> (https://bd.linkedin.com/in/prosen-ghosh-baba9aa8)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Prosen-Ghosh/even-index/issues" | ||
}, | ||
"homepage": "https://github.com/Prosen-Ghosh/even-index#readme", | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"mocha": "^4.0.0", | ||
"node-readme": "^0.1.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const evenIndex = require('../even-index'); | ||
const assert = require('chai').assert; | ||
describe('Even Index Array',function(){ | ||
it('Function Shuld Return Even Index Of Array from the orginal array',function(){ | ||
assert.deepEqual(evenIndex([1]),[1]); | ||
assert.deepEqual(evenIndex([]),[]); | ||
assert.deepEqual(evenIndex([-2,-1]),[-2]); | ||
assert.deepEqual(evenIndex([[],-2,[]]),[[],[]]); | ||
assert.deepEqual(evenIndex(["foo","baz","jam","bar","bob"]),["foo","jam","bob"]); | ||
}); | ||
}); |