Skip to content

Instantly share code, notes, and snippets.

@bryancodesjs
Created February 6, 2022 04:18
Show Gist options
  • Save bryancodesjs/962e9c46d214f8411c6fe919dbc3bd15 to your computer and use it in GitHub Desktop.
Save bryancodesjs/962e9c46d214f8411c6fe919dbc3bd15 to your computer and use it in GitHub Desktop.
my solution to hackerrank hard disk drive challenge
let space = [2,3,1,5,3,9];
let x = 2;
let results = [];
function calculateMaxDisk(seg, arr)
{
//calculate amount of modules
let module = ((arr.length) - seg) + 1;
console.log('this function will create ' + module + " iterations!");
//main loop, creates 'x' amount of iterations
for( let i=1 ; i <= module ; i++ )
{
let temporary = [];
for( let x of Array(seg).keys() )
{
temporary.push(arr[x]);
}
arr.shift();
console.log(temporary);
//sorted result
let sorted = temporary.sort((a,b) => a - b);
//console.log(sorted);
results.push(sorted[0]);
}
console.log('The minimun disk spaces found are: ')
console.log(results);
let maxVal = results.sort((a,b) => b - a);
console.log('The maximum disk space from the minimum available is: ');
console.log(maxVal[0] + "gb");
}
calculateMaxDisk(x,space);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment