//multiple answers types
var MULTIPLE_ANSWER_TYPES = [
'radio',
'checkbox',
'dropdown'
];
function hasSameProps(validSource, wannaBe, strict) {
var self = this;
//false when wannabe property is an array but validSource is not
if (typeof validSource === 'object' && Array.isArray(wannaBe)) {
return false;
}
//check for wannaBe overlapping props
if (!Object.keys(wannaBe).every(function(key) {
return validSource.hasOwnProperty(key);
})) {
// console.log('wannaBe has extra keys')
return false;
}
//check every key for being same
return Object.keys(validSource).every(function(key) {
//if object
if (typeof validSource[key] === 'object' && typeof wannaBe[key] === 'object') {
//check array is array
if (Array.isArray(validSource[key])) {
//console.log('must be array key: ' + key);
return Array.isArray(wannaBe[key]);
} else {
//recursively check nested object
return self.hasSameProps(validSource[key], wannaBe[key]);
}
} else {
//check every key is present in the wanna be object
if (wannaBe[key] === undefined) {
// console.log('wannaBe does not have key:' + key)
return false;
}
//check the type of value is the same (not the actual value, which can be different)
if (strict) {
if (typeof validSource[key] !== typeof wannaBe[key]) {
//console.log('wannaBe type is wrong for key: ' + key)
return false;
}
}
return true;
}
});
}
function areJumpsValid(input) {
var jumps = input.jumps;
var are_valid = true;
var possible_answers = input.possible_answers;
var validJumpStructure = {
to: '',
when: '',
answer_ref: ''
};
if (!$.isArray(jumps)) {
are_valid = false;
} else {
$(jumps).each(function(index, jump) {
var answer_ref_found = false;
//validate structure
...
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.