Skip to content

Instantly share code, notes, and snippets.

@zacck-zz
Created March 9, 2017 13:12
Show Gist options
  • Select an option

  • Save zacck-zz/36f3137177e7b6e1615c6cd2a9eada87 to your computer and use it in GitHub Desktop.

Select an option

Save zacck-zz/36f3137177e7b6e1615c6cd2a9eada87 to your computer and use it in GitHub Desktop.
// 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