This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
displayNumbers(50); | |
function displayNumbers($i) | |
{ | |
if($i == 0) return; | |
echo $i." "; | |
displayNumbers($i-1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fs = require('fs'), | |
readline = require('readline'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fs = require('fs'), | |
readline = require('readline'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inputFile = fs.createReadStream('my-input.txt') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rl = readline.createInterface({ | |
input: inputFile, | |
output: process.stdout | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rl.on('line', (input) => { | |
//do some code here | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rl.on('line', (input) => { | |
let splitDimensions = input.split('x'); | |
console.log( 'Surface area of', input, 'is', calculateSurfaceArea(splitDimensions), 'Volume is', calculateVolume(splitDimensions) ); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateSurfaceArea(dimensions) { | |
let sides = [2 * (dimensions[0] * dimensions[1] ), 2 * (dimensions[1] * dimensions[2]), 2 * (dimensions[0] * dimensions[2] )]; | |
return sides[0] + sides[1] + sides[2]; | |
} | |
And the calculateVolume function looks like this | |
function calculateVolume(dimensions) { | |
return dimensions[0] * dimensions[1] * dimensions[2]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rl.on('close', () => { | |
input.close(); | |
console.log('file closed'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeLargest(a, b, c) { | |
return a > b ? ( a > c ? [b, c] : [a, b] ) : ( b > c ? [a, c] : [a, b] ); | |
} |
OlderNewer