function isEquivalent(a, b) {
// Create arrays of property names
var aProps = Object.getOwnPropertyNames(a);
var bProps = Object.getOwnPropertyNames(b);
// If number of properties is different,
// objects are not equivalent
if (aProps.length !== bProps.length) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
var propName = aProps[i];
// If values of same property are not equal,
// objects are not equivalent
if (a[propName] !== b[propName]) {
return false;
}
}
// If we made it this far, objects
// are considered equivalent
return true;
}
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1)
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4()
}
class Keyframe {
constructor(config) {
this.id = guid()
this.time = null
this.properties = {}
Object.assign(this, config)
}
}
let keyframes = [
new Keyframe({
time: 0,
properties: {
opacity: 0
}
}),
new Keyframe({
time: 0.1,
properties: {
opacity: 1
}
})
]
function keyframesDiff (keyframes) {
keyframes = keyframes.sort((a, b) => a.time - b.time)
let sequences = new Array
let currentSequence = new Array
for (let index in keyframes) {
index = parseInt(index)
if (index < keyframes.length - 1) {
let current = keyframes[index]
let next = keyframes[index + 1]
if (isEquivalent(current.properties, next.properties)) {
currentSequence.push(keyframes[index])
sequences.push(currentSequence)
currentSequence = new Array
} else {
currentSequence.push(keyframes[index])
}
} else {
let current = keyframes[index]
let previous = keyframes[index - 1]
if (isEquivalent(current.properties, previous.properties)) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.