1 def count_arithmetic_slices(nums: list[int]) -> int:
2 n = len(nums)
3 dp = [0] * n
4
5 for i in range(2, n):
6 if nums[i] - nums[i-1] == nums[i-1] - nums[i-2]:
7 dp[i] = dp[i - 1] + 1
8
9 return sum(dp)
10
1 getItem(key) {
2 if (typeof window !== 'undefined' && typeof Storage !== undefined) {
3 return localStorage.getItem(key);
4 }
5
6 return null;
7 }
1 .fadein {
2 animation: fadein linear 1s;
3 }
4
5 @keyframes fadein {
6 from { opacity: 0; }
7 to { opacity: 1; }
8 }
1 const intersection = (a, b) => {
2 const bSet = new Set(b);
3 return a?.filter(value => bSet.has(value));
4 }
5
6 intersection([1, 2, 3], [1, 3, 5]) // [1, 3]
1 const isValidEmail = (email) => {
2 const emailRegex = new RegExp('[a-z0-9]+@[a-z0-9]+.[a-z]{2,4}$');
3
4 return emailRegex.test(email.toLowerCase());
5 }
1 // for PWA `standalone` property is `true`
2 const isPWA = window.navigator.standalone;
1 function slugify(value) {
2 return value
3 .toString()
4 .normalize('NFD') // split an accented letter in the base letter and the accent
5 .replace(/[\u0300-\u036f]/g, '') // remove all the accents
6 .toLowerCase()
7 .replace(/[^a-z0-9 -]/g, '') // replace all chars that are not letters, numbers and spaces
8 .trim()
9 .replace(/\s+/g, '-');}
10 slugify('Hello world'); // 'hello-world'
1 const numOfAppearances = (array, value) => {
2 return array.reduce((acc, currVal) => currVal === value ? ++acc : acc, 0);
3 };
4
5 const count = numOfAppearances(['one', 'yes', 3, 'yes', false], 'yes'); // 2