Skip to content

Commit

Permalink
fix(js): horizontal and vertical scroll improvements (#2649)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmth authored Nov 3, 2023
1 parent 16ecc54 commit 617205f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
1 change: 0 additions & 1 deletion live-examples/js-examples/bigint/bigint-asintn.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ function check64bit(number) {

check64bit(2n ** 64n);
// Expected output: "Number doesn't fit in signed 64-bit integer!"

check64bit(2n ** 32n);
// Expected output: 4294967296n
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const vehicles = ['Motorcycle', 'Bus', 'Car'];

const formatterEn = new Intl.ListFormat('en', {
style: 'long',
type: 'conjunction',
});

const formatterFr = new Intl.ListFormat('fr', {
style: 'long',
type: 'conjunction',
Expand Down
13 changes: 5 additions & 8 deletions live-examples/js-examples/string/string-indexof.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
const paragraph =
'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const paragraph = "I think Ruth's dog is cuter than your dog!";

const searchTerm = 'dog';
const indexOfFirst = paragraph.indexOf(searchTerm);

console.log(
`The index of the first "${searchTerm}" from the beginning is ${indexOfFirst}`,
);
// Expected output: "The index of the first "dog" from the beginning is 40"
console.log(`The index of the first "${searchTerm}" is ${indexOfFirst}`);
// Expected output: "The index of the first "dog" is 7"

console.log(
`The index of the 2nd "${searchTerm}" is ${paragraph.indexOf(
`The index of the second "${searchTerm}" is ${paragraph.indexOf(
searchTerm,
indexOfFirst + 1,
)}`,
);
// Expected output: "The index of the 2nd "dog" is 52"
// Expected output: "The index of the second "dog" is 41"
9 changes: 3 additions & 6 deletions live-examples/js-examples/string/string-lastindexof.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const paragraph =
'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const paragraph = "I think Ruth's dog is cuter than your dog!";

const searchTerm = 'dog';

console.log(
`The index of the first "${searchTerm}" from the end is ${paragraph.lastIndexOf(
searchTerm,
)}`,
`Index of the last ${searchTerm} is ${paragraph.lastIndexOf(searchTerm)}`,
);
// Expected output: "The index of the first "dog" from the end is 52"
// Expected output: "Index of the last "dog" is 38"
11 changes: 5 additions & 6 deletions live-examples/js-examples/string/string-replace.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const p =
'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
const paragraph = "I think Ruth's dog is cuter than your dog!";

console.log(p.replace('dog', 'monkey'));
// Expected output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"
console.log(paragraph.replace("Ruth's", 'my'));
// Expected output: "I think my dog is cuter than your dog!"

const regex = /Dog/i;
console.log(p.replace(regex, 'ferret'));
// Expected output: "The quick brown fox jumps over the lazy ferret. If the dog reacted, was it really lazy?"
console.log(paragraph.replace(regex, 'ferret'));
// Expected output: "I think Ruth's ferret is cuter than your dog!"
11 changes: 5 additions & 6 deletions live-examples/js-examples/string/string-replaceall.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const p =
'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
const paragraph = "I think Ruth's dog is cuter than your dog!";

console.log(p.replaceAll('dog', 'monkey'));
// Expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
console.log(paragraph.replaceAll('dog', 'monkey'));
// Expected output: "I think Ruth's monkey is cuter than your monkey!"

// Global flag required when calling replaceAll with regex
const regex = /Dog/gi;
console.log(p.replaceAll(regex, 'ferret'));
// Expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
console.log(paragraph.replaceAll(regex, 'ferret'));
// Expected output: "I think Ruth's ferret is cuter than your ferret!"
11 changes: 5 additions & 6 deletions live-examples/js-examples/string/string-search.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const paragraph =
'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const paragraph = "I think Ruth's dog is cuter than your dog!";

// Any character that is not a word character or whitespace
const regex = /[^\w\s]/g;
// Anything not a word character, whitespace or apostrophe
const regex = /[^\w\s']/g;

console.log(paragraph.search(regex));
// Expected output: 43
// Expected output: 41

console.log(paragraph[paragraph.search(regex)]);
// Expected output: "."
// Expected output: "!"

0 comments on commit 617205f

Please sign in to comment.