Skip to content

Instantly share code, notes, and snippets.

@kopasetik
Last active August 29, 2015 14:04
Show Gist options
  • Save kopasetik/aea97c4851fc128e6be7 to your computer and use it in GitHub Desktop.
Save kopasetik/aea97c4851fc128e6be7 to your computer and use it in GitHub Desktop.
Trying to make this asynchronous
// create array to hold the values that the memory tiles will hold
var memory_values = [];
// create array for the locations of the tiles themselves
var memory_tile_ids = [];
// initialize array for the tiles flipped
var tiles_flipped = 0;
function onLinkedInLoad() {
IN.Event.on(IN, "auth", function() {
onLinkedInLogin();
});
IN.Event.on(IN, "logout", function() {
onLinkedInLogout();
});
}
function onLinkedInLogout() {
// setConnections({}, {total:0});
}
function onLinkedInLogin() {
// here, we pass the fields as individual string parameters
IN.API.Connections("me")
.fields("id", "firstName", "lastName", "pictureUrl", "publicProfileUrl")
.result(function(result) {
listConnections(result.values, arrFilter);
})
.error(function(err){
alert(err);
});
}
function listConnections(connections, callback) {
callback(connections, shuffleArray1);
}
function arrFilter(arr, callback) {
var filteredArr = arr
.filter(function(element){
return element["id"] != "private";
});
callback( filteredArr, arrLimit12 );
}
function shuffleArray1(arr, cb){
var i = arr.length,
j,
temp;
// i starts at the length of the array
// then immediately decrements
while( --i > 0 ){
// reshuffles the array tiles randomly
j = Math.floor(Math.random() * ( i + 1 ));
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
cb(arr, createMemoryBoardArray);
}
function arrLimit(arr, arrLen){
return arr
.slice(0,arrLen);
}
function arrLimit12(arr, cb){
var newArr = arrLimit(arr, 12);
// cb = createMemoryBoardArray
cb( newArr , newBoard);
}
function createMemoryBoardArray(objArr, cb) {
var linkinBoard = [];
objArr.forEach(function(element){
linkinBoard.push({
linkinType: "name",
id: element["id"],
name: element["firstName"] + " " + element["lastName"]
});
linkinBoard.push({
linkinType: "image",
id: element["id"],
imageUrl: element["pictureUrl"]
});
});
// cb = newBoard
cb(linkinBoard, shuffleArray2, '');
}
// And it keeps going on like this...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment