const duplicates = Array
.from(arr.reduce((acc, n) => acc.set(n.id, acc.has(n.id)), new Map))
.reduce((acc, n) => (n[1] && acc.push(n[0]), acc), []);
// или
const duplicates = Object
.entries(arr.reduce((acc, n) => (acc[n.id] = (acc[n.id] || 0) + 1, acc), {}))
.filter(n => n[1] > 1)
.map(n => +n[0]);
// или
const duplicates = [...arr
.reduce((acc, n) => (acc[+acc[0].has(n.id)].add(n.id), acc), [ new Set, new Set ])
.pop()
];
// или
const duplicates = arr
.map(n => n.id)
.filter((n, i, a) => i !== a.indexOf(n))
.filter((n, i, a) => i === a.indexOf(n));
// или
const duplicates = arr.reduce((acc, { id: n }, i, a) => (
!acc.includes(n) && i !== a.findIndex(m => m.id === n) && acc.push(n),
acc
), []);
<select ref="selectr" v-model="selected" @input="onInput(e)">
<option v-for="(item, index) of list" :key="index" :value="item">{{ item }}</option>
</select>
selected: {
get() {
return this.vuex;
},
set(value) {
if (window.confirm("Realy change select?")) {
this.vuex = value;
} else {
this.$refs.selectr.value = this.vuex;
}
}
}
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
// ...
function walk(node) {
if (node) {
console.log(node);
walk(node.next);
}
}
function walk(node) {
while (node) {
console.log(node);
node = node.next;
}
}
#include <iostream>
template <class Body>
void call(const Body& body) {
body();
};
void test() {
std::cout << "function" << std::endl;
}
int main() {
call(test);
call([]() {
std::cout << "lambda" << std::endl;
});
return 0;
}
Если можете, приведите примеры использования данного метода, ну и конечно объясните мне мои вопросы, спасибо!
Function.prototype.method = function(name, func){
this.prototype[name] = func;
return this
};
function Person(name) {
this.name = name
}
Person
.method('say', function() {
console.log('dude!')
})
.method('myName', function() {
console.log(this.name)
});
var person = new Person('Alex')
person.say() // dude!
person.myName() // Alex
#include <iostream>
using namespace std;
const char ssid[] = "TEST";
const char password[] = "123456";
struct Wifi {
const char *access[2][2];
} wifi{
{
{ ssid, password },
{ "DIR", "654321" }
}
};
int main() {
for (int i = 0; i < sizeof(wifi.access) / sizeof(wifi.access[0]); i++) {
cout << wifi.access[i][0] << ": " << wifi.access[i][1] << '\n';
// TEST: 123456
// DIR: 654321
}
return 0;
}