Skip to content

Instantly share code, notes, and snippets.

@areagray
Created January 21, 2014 22:27
Show Gist options
  • Save areagray/8549770 to your computer and use it in GitHub Desktop.
Save areagray/8549770 to your computer and use it in GitHub Desktop.
Coderbyte: Have the function ThirdGreatest(strArr) take the array of strings stored in strArr and return the third largest word within in. So for example: if strArr is ["hello", "world", "before", "all"] your output should be world because "before" is 6 letters long, and "hello" and "world" are both 5, but the output should be world because it a…
//Coderbyte
function ThirdGreatest(strArr) {
var matrix=[];
//build the array, two dimensions
for (var i=0; i<strArr.length;i++){
matrix.push([strArr[i].length,strArr[i]]);
}
//sort
matrix.sort(function(a,b){
return b[0]>a[0];
});
//grab the 3rd greatest
return matrix[2][1]);
}
@pritam-shinde
Copy link

function ArrayChallenge(strArr) {
var matrix=[];

//build the array, two dimensions  
for (var i=0; i<strArr.length;i++){
	matrix.push([strArr[i].length,strArr[i]]);
}
//sort

matrix = matrix.sort()
matrix = matrix.slice(1, matrix.length-1)
return matrix[0][1]
}
// keep this function call here
console.log(ArrayChallenge(readline()));
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment