Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
function maxMin(k, arr) {
const sortedlist = arr.map((x) => x).sort((a, b) => a - b);

let result = sortedlist[sortedlist.length - 1] - sortedlist[0];
let result = sortedlist.at(-1) - sortedlist[0];

for (let i = 0; i < sortedlist.length - k + 1; i++) {
const tmin = sortedlist[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
function minimumAbsoluteDifference(arr) {
const sortedNums = arr.map((x) => x).sort((a, b) => b - a);

let result = Math.abs(sortedNums[sortedNums.length - 1] - sortedNums[0]);
let result = Math.abs(sortedNums.at(-1) - sortedNums[0]);

for (let i = 0; i < sortedNums.length - 1; i++) {
const aValue = sortedNums[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export default {
comparatorSorting,
comparatorSortingPrint
};
export { Player, SortablePlayer, comparatorSorting, comparatorSortingPrint };
export { Player } from './ctci_comparator_sorting.Player.js';
export { SortablePlayer, comparatorSorting, comparatorSortingPrint };
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ function isBalancedCompute(s) {
for (const letter of s.split('')) {
if (letter in pairs) {
brackets.push(letter);
} else if (
brackets.length > 0 &&
pairs[brackets[brackets.length - 1]] === letter
) {
} else if (brackets.length > 0 && pairs[brackets.at(-1)] === letter) {
brackets.pop();
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/projecteuler/problem0005.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function _replaceMaximum(_element, count, _group) {
const group = _group;
if (Object.hasOwn(group, _element)) {
const elem = _group[_element];
group[_element] = count > elem ? count : elem;
group[_element] = Math.max(count, elem);
} else {
group[_element] = count;
}
Expand Down
2 changes: 1 addition & 1 deletion src/projecteuler/problem0007.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function problem0007(_top) {

console.log(`primes count: ${primes.length}`);

const answer = primes[primes.length - 1];
const answer = primes.at(-1);

const cycles = i;
console.log(`${_top} prime number is: ${answer} in ${cycles} cycles`);
Expand Down
2 changes: 1 addition & 1 deletion src/projecteuler/problem0017.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function problem0017(init, last) {

for (let i = init; i <= last; i++) {
word = numberToWord(i);
replaced = word.replace(/[^a-z0-9]/gi, '');
replaced = word.replaceAll(/[^a-z0-9]/gi, '');

acum += replaced.length;

Expand Down
2 changes: 1 addition & 1 deletion src/projecteuler/problem0018.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function problem0018(_triangle) {
console.debug('leafs count', leafs.length, 'leafs', leafs);

const __START_FROM__ = 0;
const max = leafs.reduce((a, b) => (a > b ? a : b), __START_FROM__);
const max = leafs.reduce((a, b) => Math.max(a, b), __START_FROM__);

return max;
}
Expand Down