function countContiguousDistinct(k, arr) {
const counts = [];
let distinct = 0;
const result = [];
for (let i = 0; i < k; i += 1) {
const val = arr[i];
if (counts[val] === undefined) {
counts[val] = 0;
distinct += 1;
}
counts[val] += 1;
}
result.push(distinct);
for (let i = k; i < arr.length; i += 1) {
const lVal = arr[i - k];
counts[lVal] -= 1;
if (counts[lVal] === 0) {
distinct -= 1;
}
const rVal = arr[i];
if (counts[rVal] === undefined) {
counts[rVal] = 0;
}
if (counts[rVal] === 0) {
distinct += 1;
}
counts[rVal] += 1;
result.push(distinct);
}
return result;
}
# Schema (MySQL v8.0)
CREATE TABLE `test` (
`id` INT,
`json` JSON
);
INSERT INTO `test` VALUES
(1, '{"2022-01-01": 4, "2022-05-05": 10, "2022-09-09": 9}'),
(2, '{"2022-05-01": 4, "2022-01-05": 10, "2022-03-09": 9}');
# Query #1
WITH `cte` AS (
SELECT `t`.`id`, MAX(`j`.`json_key`) AS `key`
FROM `test` AS`t`
JOIN JSON_TABLE(
JSON_KEYS(`json`), '$[*]' COLUMNS(`json_key` JSON PATH '$')
) AS `j`
GROUP BY `t`.`id`
)
SELECT `t`.`id`, `c`.`key`,
JSON_EXTRACT(`t`.`json`, CONCAT('$.', `c`.`key`)) AS `val`
FROM `cte` AS `c`
JOIN `test` AS `t` ON `t`.`id` = `c`.`id`
# Result
| id | key | val |
| --- | ------------ | --- |
| 1 | "2022-09-09" | 9 |
| 2 | "2022-05-01" | 4 |
const today = String((new Date()).getDate()).padStart(2, '0');
const dayStartElements = document.querySelectorAll(".js-text");
dayStartElements.forEach((el) => { el.innerText = `${dd}` });
If the handler throws an error or returns a rejected promise, the promise returned by finally() will be rejected with that value instead. Otherwise, the return value of the handler does not affect the state of the original promise.
...
UnlikePromise.resolve(2).then(() => 77, () => {})
(which will return a resolved promise with the result 77),Promise.resolve(2).finally(() => 77)
will return a new resolved promise with the result 2.
Similarly, unlikePromise.reject(3).then(() => {}, () => 88)
(which will return a resolved promise with the value 88),Promise.reject(3).finally(() => 88)
will return a rejected promise with the reason 3.
But, bothPromise.reject(3).finally(() => {throw 99})
andwill reject the returned promise with the reason 99.Promise.reject(3).finally(() => Promise.reject(99))
function find(sum, n, m) {
if (n === 1) {
return [`${sum}`];
}
const result = [];
const min = Math.max(m, Math.floor(sum - (n - 1) * 9));
const max = Math.floor(sum / n);
for (let i = min; i <= max; i += 1) {
find(sum - i, n - 1, i).forEach((el) => result.push(`${i}${el}`));
}
return result;
}
function findAll(sum, n) {
if (sum > n * 9 || sum < n) {
return [];
}
const result = find(sum, n, 1);
return [result.length, result[0], result.pop()];
}
SELECT DISTINCT FIRST_VALUE(`id`) OVER `win` AS `id`, `user_id`,
FIRST_VALUE(`score`) OVER `win` AS `score`,
FIRST_VALUE(`user_name`) OVER `win` AS `user_name`
FROM `game_api_score`
WINDOW `win` AS (PARTITION BY `user_id` ORDER BY `score` DESC)