const groups = [
{ id: 1, name: 'group 1', items_ids: [1, 2, 4] },
{ id: 2, name: 'group 2', items_ids: [8, 2, 3] },
{ id: 3, name: 'group 3', items_ids: [12, 1] },
{ id: 4, name: 'group 4', items_ids: [] },
{ id: 5, name: 'group 5', items_ids: [] },
]
const result = groups
.filter(group => group.items_ids.length > 0)
.reduce((prev, next, i, acc) => prev.concat(next.items_ids), [])
console.clear()
console.log(result) // [1, 2, 4, 8, 2, 3, 12, 1]
console.log([...new Set(result)]) // [1, 2, 4, 8, 3, 12]
let dictionary = {
'Hello': 'Привет',
'Bye': 'Пока'
}
dictionary = new Proxy(dictionary, {
get(target, phrase) {
if (phrase in target) {
return target[phrase]
} else {
console.log(`No phrase: ${phrase}`)
return phrase
}
}
})
// Обращаемся к произвольным свойствам словаря!
alert( dictionary['Hello'] ) // Привет
alert( dictionary['Welcome']) // Welcome (без перевода)
let res = this.sendForm('logout')
.done(function(){
getUserInfo(); // это не функция, а метод. Почему вы так вызываете?
});
let vm = this; // зачем эта дичь?
const vm = new Vue({
el: '#navbar',
data () {
return {
user: {}
}
},
methods: {
getUserInfo () {
$.ajax({
type: 'GET',
url: config.apiHost + apiRoutes.getUserInfo,
dataType: 'json'
})
.done((res) => {
if (!res.error) {
vm.user = res.data
}
})
},
loginLocal () {
this.sendForm('loginLocal')
.done(() => vm.getUserInfo())
},
logout (e) {
this.sendForm('logout')
.done(() => vm.getUserInfo())
}
}
})
app.get('/api/v1', function middleware (req, res, next) {
// this function is middleware
req.locals.middlewareObject = { name: 'middleware', called: true }
next()
}, function otherMiddleware (req, res, next) {
// this function is middleware too
return res.json(req.locals.middlewareObject)
})
#!/bin/bash
set -e
FOLDER="photos"
mkdir -p $FOLDER
function download () {
local url=$1
local name=$2
filename=$(basename "$url")
extension="${filename##*.}"
wget -O"${FOLDER}/${name}.${extension}" "${url}"
}
while read line
do
name=$(echo $line | awk -F ";" ' {print $1} ' | sed -e "s/\ /_/g")
url=$(echo $line | awk -F ";" ' {print $2} ')
download "${url}" "${name}"
done < $1
$ ./script.sh table.csv
Ярков Алексей Николаевич;https://avatars2.githubusercontent.com/u/6022892?v=4&s=460
Иванов Иван Иванович;https://avatars2.githubusercontent.com/u/23380632?v=4&s=460