After going through the Basic Algorithm, I’m definitely noticing I’ll need to start looking at other sources along with FCC to progress. A lot of the solutions needed are using functions and elements that weren’t taught in the Front End Dev Cert section.

function largestOfFour(arr) {
//array for storing largest numbers
var largestArr = [];
var largest = 0;//create largest number to have something to compare to
//Loop through an array
for(var i=0; i< arr.length; i++){
//loop through an indicidual numbers of each array
for(var y=0; y< arr[i].length; y++){
//compare each number to our largest number declared earlier
if(arr[i][y] > largest){
largest = arr[i][y];
}
}
largestArr.push(largest);//add largest number to an array
largest = 0;//reset largest number for the next loop phase
}
return largestArr;
}
//test
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

I don’t know about you guys, but those solutions in spoiler section are a bit complicate. Maybe bc I’m new to programming. Anyway after a couple of hours ;-), with breaks I came with my own algorithm:

function largestOfFour(arr) {
var newArr = [];
for(var i = 0; i < arr.length; i++){
newArr[i] = Math.max.apply(null, arr[i]);
}
return newArr;
}
largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]);

Up to this point I’ve been struggling with coming up with some “slick” code compared to the hints.But in this case I think I’ve leaped ahead. This compact solution will work for any number of arrays and any number values in a sub-array:

function largestOfFour(arr) {
if (Array.isArray(arr)) {
subArray = [];
for (i = 0; i < arr.length; i++) {
subArray.push(Math.max.apply(null, arr[i])) ;
}
return subArray;
}
return "Not an Array";
}
largestOfFour([[4, 5, 1, 3, 9], [13, 27, 18, 26], [32, 35, 37, 39,101], [1000, 1001, 857, 1], [1000, 2001, 857, 1]]);

function largestOfFour(arr) {
// You can do this!
var result = [];
var max = 0;
for(var i=0;i<arr.length;i++) {
for(var j=0;j<arr.length;j++) {
if(arr[i][j]>max) {
max = arr[i][j];
}

function largestOfFour(arr) {
// You can do this!
var max=0;
var array=[];
for(var i=0;i<arr.length;i++)
{
for(var j=0;j<arr[i].length;j++)
{
if(arr[i][j]>max)
max=arr[i][j];
}
array[i]=max;
max=0;
}
arr=array;
return arr;
}

I’ve seen a lot of similar solutions but I thought I’d post mine for comparison:
function largestOfFour(array) {
var arr = []; //sub-array
var ans = [];// array of answers
for(i = 0; i < array.length; ++i)
{
arr = array[i];
/.push adds data to end of ans, .sort sorts the data(small - big) then gives the
last element (the biggest number)./
ans.push(arr.sort(function(b, a){return a < b;})[3]); //
}
return ans;
}

Seem to have found a quick elegant way - found something similar to the basic solution and when trying to recreate the intermediate solution this seemed to work for everything:

function largestofFour(arr) {
arr.reduce(function(a,b) {
return b-a;
});
}

I used sort. Here is my solution.
function largestOfFour(arr) {
var newArray = [];
for (var i = 0; i < arr.length; i++) {
arr[i].sort(function(a, b){
return b - a;
});
newArray.push(arr[i][0]);
}
return newArray;
}

Is that acceptable? I’ve only been learning for a week, so the intermediate and advanced solutions are tough for me to decipher, while the beginner solution seems overly complicated.

function largestOfFour(arr) {
//Combined Array to store result of each largest subarray
let combinedArr = [];
//Iterate array + child arrays
for (let i=0; i<arr.length; i++){
//Benchmark / reset for subarray compare
let curMax = 0;
//Compare subarray for max value
for (let j=0; j<arr[i].length; j++){
if (curMax <= arr[i][j]){
curMax = arr[i][j];
}
}
//Store largest number in new array current index
combinedArr[i]=curMax;
}
return combinedArr;
}
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

I don’t know what’s strange but I think my solution is too small compared with your solutions guys !! if there is anything wrong, please tell me.
here is it

function largestOfFour(arr) {
var result = [];

for (var x = 0 ; x < arr.length ; x++){
arr[x].sort(function(a,b){return a-b;});
result[x] = arr[x].pop();
}
return result;
}