Last active
December 10, 2020 18:42
-
-
Save leomonteiro92/5a6fe55c286c4bc1c33db98590a26279 to your computer and use it in GitHub Desktop.
Developer interview test
This file contains hidden or 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
'use strict' | |
const fs = require('fs'); | |
fs.readFile('lista_palavras_desordenada.txt', (err, data) => { | |
if (err) throw err; | |
const array = data.toString() | |
.trim() | |
.split('\n'); | |
const result = array.filter(item => { | |
let str = item.trim(); | |
return str[str.length - 1] === 'a'; | |
}).length; | |
console.log(`Problema #1 R: ${result}`); | |
}); |
This file contains hidden or 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
'use strict' | |
const fs = require('fs'); | |
fs.readFile('lista_palavras_desordenada.txt', (err, data) => { | |
if (err) throw err; | |
const array = data.toString() | |
.trim() | |
.split('\n'); | |
const result = array.filter(item => { | |
let str = item.trim().split(''); | |
let sum = str.reduce((sum, char) => { | |
return sum + char[0].charCodeAt(0) - 97; | |
}, 0); | |
return sum % 5 === 0; | |
}).length; | |
console.log(`Problema #2 R: ${result}`); | |
}); |
This file contains hidden or 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
'use strict' | |
const fs = require('fs'); | |
function Tree(value) { | |
this.value = value; | |
this.right = null; | |
this.left = null; | |
} | |
Tree.prototype.push = function (value) { | |
if (value <= this.value) { | |
if (!this.left) this.left = new Tree(value); | |
else this.left.push(value); | |
} else if (value > this.value) { | |
if (!this.right) this.right = new Tree(value); | |
else this.right.push(value); | |
} | |
}; | |
Tree.prototype.search = function (value, sum) { | |
if (this.value === value) { | |
sum += this.value; | |
} | |
if (this.left) { | |
sum += this.left.value; | |
this.left.search(value, sum); | |
} | |
if (this.right) { | |
sum += this.right.value; | |
this.right.search(value, sum) | |
} | |
return sum; | |
} | |
fs.readFile('numeros.txt', (err, data) => { | |
if (err) throw err; | |
const array = data.toString() | |
.trim() | |
.split('\n'); | |
let root = new Tree(array[0]); | |
let i = 1; | |
while (i < array.length) { | |
root.push(parseInt(array[i])); | |
i++; | |
} | |
console.log(`Problema #3: ${root.search(83099, 0)}`); | |
}); |
This file contains hidden or 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
'use strict' | |
const fs = require('fs'); | |
fs.readFile('triangulo.txt', (err, data) => { | |
if (err) throw err; | |
const array = data.toString() | |
.trim() | |
.split('\n').map(item => { | |
return item.trim().split(' '); | |
}); | |
const length = array.length - 1; | |
function matchBest(...args) { | |
let a = parseInt(args[0]); | |
let b = parseInt(args[1]); | |
let c = parseInt(args[2]); | |
if ((a + b) >= (a + c)) | |
return (a + b); | |
else | |
return (a + c); | |
} | |
function sum(row) { | |
if (row === -1) return array[0][0]; | |
for (let i = 0; i <= row; i++) { | |
array[row][i] = matchBest( | |
array[row][i], | |
array[row + 1][i], | |
array[row + 1][i + 1] | |
) | |
} | |
array.pop(); | |
sum(row - 1); | |
} | |
sum(length - 1); | |
console.log(`Problema #4 R: ${array[0][0]}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment