function Stack() {
this._size = 0;
this._storage = {};
}
Stack.prototype.push = function(data) {
var size = ++this._size;
this._storage[size] = data;
};
Stack.prototype.pop = function() {
var size = this._size,
deletedData;
if (size) {
deletedData = this._storage[size];
delete this._storage[size];
this._size--;
return deletedData;
}
};
class Stack {
constructor() {
this.stack = []
}
// Inserts the element into the top of the stack
push(element) {
this.stack.push(element)
}
// Removes the element from the top of the stack and return that element
pop() {
if (this.isEmpty()) return 'Stack is empty!'
return this.stack.pop()
}
// Return which element is on top of the stack
peek() {
if (this.isEmpty()) return 'Stack is empty'
return this.stack[this.stack.length - 1]
}
// helper method
isEmpty() {
return !this.stack.length
}
}
<div class="preloader">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
.circle {
background: grey;
display: inline-block;
border-radius: 50%;
width: 20px;
height: 20px;
animation: preloader 1s infinite linear;
}
.circle:nth-child(1) { animation-delay: 0s; }
.circle:nth-child(2) { animation-delay: 0.2s; }
.circle:nth-child(3) { animation-delay: 0.4s; }
@keyframes preloader {
0%, 40% {
background: grey;
}
20% {
background: black;
}
}
создал физическую папку, в нем разместил index.php - выходит циклический редирект
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
DirectorySlash Off
, но тогда нужны дополнительные правила, чтобы при обращении к существующей папке работал размещённый в ней index.php.function createObject(input) {
let output = {}
Object.keys(input).map((item, idx) => {
let inputValue = input[Object.keys(input)[idx]],
arr = item.split('.'),
[mainKey, subKey] = arr;
if (typeof output[mainKey] === 'undefined') output[mainKey] = arr.length > 2 ? [] : {};
if (Array.isArray(output[mainKey])) {
let obj = new Object();
obj[subKey] = inputValue;
output[mainKey].push(obj);
} else {
output[mainKey][subKey] = inputValue;
}
});
return output;
}
const getOutput = input => {
let obj = {}
for(key in input) {
let keyArr = [...key.split('.')]
if(obj[keyArr[0]]) {
obj[keyArr[0]].push({[keyArr[keyArr.length - 1]]: input[key]})
} else {
obj[keyArr[0]] = [{[keyArr[keyArr.length - 1]]: input[key]}]
}
}
for(key in obj) {
if(obj[key].length === 1) obj[key] = obj[key][0]
}
return obj
}
{
᠌ ᠌᠌ ᠌ ᠌ "foo": {
᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ "0": {
᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ "first": 111
᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ },
᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ "1": {
᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ "first": 222
᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ }
᠌ ᠌᠌ ᠌ ᠌ },
᠌ ᠌᠌ ᠌ ᠌ "bar": {
᠌ ᠌᠌ ᠌ ᠌ ᠌ ᠌᠌ ᠌ ᠌ "second": 333
᠌ ᠌᠌ ᠌ ᠌ }
}
const insert = (target,path,value) => path.split(".").reduce((a,k,i,l)=>a[k]=i+1==l.length?value:a[k]||{},target);
const parse = (list,result={}) => Object.keys(list).forEach(k=>insert(result,k,list[k]))||result;
const output = parse(input);
function setVal(obj, path, val) {
const keys = path.split('.');
const key = keys.pop();
keys.reduce((p, c) => p[c] = p[c] || {}, obj)[key] = val;
return obj;
}
function replaceObjWithArr(obj) {
if (obj instanceof Object) {
const keys = Object.keys(obj).sort((a, b) => a - b);
obj = keys.every((n, i) => +n === i) ? keys.map(n => obj[n]) : obj;
keys.forEach(n => obj[n] = replaceObjWithArr(obj[n]));
}
return obj;
}
const output = replaceObjWithArr(Object
.entries(input)
.reduce((acc, n) => setVal(acc, ...n), {})
);
sitemap.xml
и положить в корень сайта.