Created
March 9, 2017 13:12
-
-
Save zacck-zz/36f3137177e7b6e1615c6cd2a9eada87 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // you can write to stdout for debugging purposes, e.g. | |
| // console.log('this is a debug message'); | |
| function solution(A) { | |
| // write your code in JavaScript (Node.js 6.4.0) | |
| //number of pairs | |
| var pairs = 0; | |
| //TODO use recursion. | |
| //map through array | |
| A.map((item, pos, itemArray) => { | |
| //we the item the postion and array | |
| //lets chek all values after this for similar | |
| itemArray.map((laterItem, laterPos, laterArray) => { | |
| //check that the item appeas after | |
| //check that the item is identical | |
| if(laterPos > pos && laterItem == item) { | |
| //if so lets increment the pairs | |
| pairs++; | |
| } | |
| }) | |
| }) | |
| //lets return the pairs | |
| return pairs | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment