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
lista = [] | |
agenda = {} | |
def listAll(): | |
print('----- AGENDA -----') | |
for i in lista: | |
for chave, valor in i.items(): | |
print(chave.title(), valor) | |
print('----- FIM -----') |
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
// Without reduce | |
function diagonalDifference(arr) { | |
let sum = 0; | |
for (let i = 0; i <= arr.length - 1; i++) { | |
sum += arr[i][i] - arr[i].reverse()[i]; | |
} | |
return Math.abs(sum); | |
} | |
// With reduce |
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 stockAndCount(n, arr) { | |
let pairs = 0; // pairs number | |
const colors = arr.reduce((acc, val) => { | |
acc[val] ? (acc[val] += 1) : (acc[val] = 1); | |
return acc; | |
}, {}); // return an object with colors (numbers) as keys and quantity as value | |
Object.keys(colors).forEach((n) => { // for each key in colors | |
let _pair = parseInt(colors[n] / 2); // looks for even numbers | |
if (_pair >= 1) pairs += _pair; // total |
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
// Without Reduce | |
function simpleArraySum(ar) { | |
let total = 0; | |
for(let elem in ar) { | |
total += ar[elem] | |
} | |
return total; | |
} | |
// With Reduce |
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
console.time('test'); | |
const saldosQtd = [ | |
{ | |
qtd: 1 | |
}, | |
{ | |
qtd: 10 | |
} | |
]; |
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 onChange(control, oldValue, newValue, isLoading) { | |
if (isLoading || newValue == '' || newValue == 'false') { | |
return; | |
} | |
var multiRowSysId = 'sys_id'; | |
var checkBoxField = 'os_horarios_forao_totalmente_preenchidos'; | |
// Mensagem de erro |
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
// DEBUG | |
// Printing objects on console | |
const foo = {name: 'tom', age: 30}; | |
const bar = {name: 'harry', age: 50}; | |
const baz = {name: 'john', age: 19}; | |
console.log({ foo, bar, baz }) // To show objects names on console. | |
// Styling with css | |
console.logo('%c My friends', 'color: orange; font-weight: bold'); | |
// Console table |
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
// FILTER | |
/* | |
If i already have an array but i only want to have items in the array that match certain criteria, use the filter. | |
Quando eu já tenho um array e quero apenas itens no novo array que correspondem a uma condição, use filter. | |
*/ | |
// GET JUST EVEN NUMBERS | |
let arr = [-200, -163, -26, -4, 0, 7, 76]; |
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
/** | |
* Constructs an object from a array, using even indexes as key and odd indixes as value | |
* | |
* @param {Array} myArray - Array to be transformed | |
* @returns {Object} | |
*/ | |
function toObject(myArray) { | |
let r = {}; | |
for (let i = 0; i < myArray.length; i += 2) { | |
let key = (myArray[i]), |
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
/** | |
* Normalize strings to a custom pattern, tempplate | |
* | |
* @param {string} myStr - String to be normalized | |
* @returns {string} Normalized string | |
*/ | |
function fixStr(myStr) { | |
return myStr.normalize('NFD') | |
.replace(/\uFFFD/g, '') | |
.replace(/[\u0300-\u036f]/g, '') |
NewerOlder