Skip to content

Instantly share code, notes, and snippets.

@petercr
Created February 22, 2022 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petercr/1ad701864361123af749456774880042 to your computer and use it in GitHub Desktop.
Save petercr/1ad701864361123af749456774880042 to your computer and use it in GitHub Desktop.
My Solution To The Lonely Interger Problem in JavaScript
/*
* Complete the 'lonelyinteger' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY a as parameter.
*/
function lonelyinteger(a) {
// If a is only 1 int long just return it
if(a.length == 1) {
return a;
} else {
// outer for loop to check values with
outer: for( let i=0; i<a.length; i++) {
// inner for loop to check values with
inner: for (let j=0; j<a.length; j++) {
if(i===j) {
continue inner;
} else {
if( a[i] === a[j]) {
continue outer;
}
}
}
return a[i];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment