How to use maxDepth method in ava

Best JavaScript code snippet using ava

index.js

Source:index.js Github

copy

Full Screen

...324 * Walks through the entire object tree to return the maximum number of layers it contains.325 * @param {Any} identity326 * @param {Optional Number} maxDepth327 */328function maxDepth(identity,maxLayer=null){329 let R = 0;330 function _maxDepth(identity,maxLayer,currentDepth=0){331 if(R < currentDepth) R = currentDepth; 332 if(maxLayer!==null) if(currentDepth >= maxLayer) return;333 if(isIterable(identity)){334 var keys = Object.keys(identity);335 keys.forEach( key => {336 var subIdentity = identity[key];337 _maxDepth(subIdentity,maxLayer,currentDepth + 1);338 });339 }340 }341 _maxDepth(identity,maxLayer);342 return R;343}344/**345 * Performs deep search for identity on collection, returns the number of matches found.346 * @param {Any} collection347 * @param {Any} identity348 * @param {Number} nthDepth349 * @param {Optional Number} maxDepth350 * @return {Any} Returns number of matches found.351 */352function countMatches(collection,identity,nthDepth=null,maxDepth=null){353 var 354 depth,355 nthDepth_isNull = nthDepth === null,356 maxDepth_isNull = maxDepth === null;357 if(nthDepth_isNull && maxDepth_isNull) 358 depth = null;359 else360 if(!nthDepth_isNull && !maxDepth_isNull)361 if(nthDepth < maxDepth) depth = nthDepth; else depth = maxDepth;362 else363 if(nthDepth) depth = nthDepth; else depth = maxDepth;364 var paths = locateAll(collection,identity,depth);365 if(paths===false) return 0;366 if(nthDepth===null) return paths.length;367 if(getType(nthDepth)==='number'){368 let count = 0;369 paths.forEach( path => { 370 path = path.split('.');371 if(path.length===nthDepth) count++;372 });373 return count;374 }375 return undefined;376}377 /**378 * Performs deep search for each identity on collection, to shorten the identities to those that meets the match criteria379 * @param {Any} collection380 * @param {Any} identities381 * @param {Any} property382 * @param {Optional Number} maxDepth383 * @return {Any} Returns a collection of the same type as the 'identities' parameter provided with only the identities that matched.384 */385function onlyFalsy(collection,identities,property,maxDepth=null){386 if(getType(identities)==='array'){387 let result = [];388 identities.forEach( identity => { 389 const subCollection = deepFilter(collection,identity);390 if(isTruthy(subCollection))391 if(foundFalsy(subCollection,property,maxDepth)) result.push(identity);392 });393 return result;394 }395 if(getType(identities)==='object'){396 let result = {};397 Object.keys(identities).forEach( key => {398 const399 identity = identities[key],400 subCollection = deepFilter(collection,identity);401 if(isTruthy(subCollection))402 if(foundFalsy(subCollection,property,maxDepth)) result[key] = identity;403 });404 return result;405 }406 if(foundFalsy(collection,property,maxDepth)) return identities;407}408/**409 * Performs deep search on collection to find any match to the property and evalutates if truthy410 * @param {Any} collection411 * @param {Property} identity412 * @param {Optional Number} maxDepth413 * @return {boolean} If match confirmed and truthy will return true, otherwise false414 */415function foundFalsy(collection,identity,maxDepth=null){416 identity = singleProperty(identity);417 if(isFalsy(identity)) return undefined;418 function _foundFalsy(collection,identity,maxDepth,currentDepth=0){419 if(containsKeys(collection,[identity])) return isFalsy(collection[identity]);420 if(maxDepth!==null) if(currentDepth >= maxDepth) return false;421 if(isIterable(collection))422 for(var i = 0, keys = Object.keys(collection), l = keys.length; i < l; i++ ){423 const 424 key = keys[i], subcollection = collection[key],425 res = _foundFalsy(subcollection,identity,maxDepth,currentDepth + 1);426 if(res) return true;427 }428 return false;429 }430 return _foundFalsy(collection,identity,maxDepth);431}432/**433 * Performs deep search for each identity on collection, to shorten the identities to those that meets the match criteria434 * @param {Any} collection435 * @param {Any} identities436 * @param {Any} property437 * @param {Optional Number} maxDepth438 * @return {Any} Returns a collection of the same type as the 'identities' parameter provided with only the identities that matched.439 */440function onlyTruthy(collection,identities,property,maxDepth=null){441 if(getType(identities)==='array'){442 let result = [];443 identities.forEach( identity => { 444 const subCollection = deepFilter(collection,identity);445 if(isTruthy(subCollection))446 if(foundTruthy(subCollection,property,maxDepth)) result.push(identity);447 });448 return result;449 }450 if(getType(identities)==='object'){451 let result = {};452 Object.keys(identities).forEach( key => {453 const454 identity = identities[key],455 subCollection = deepFilter(collection,identity);456 if(isTruthy(subCollection))457 if(foundTruthy(subCollection,property,maxDepth)) result[key] = identity;458 });459 return result;460 }461 if(foundTruthy(collection,property,maxDepth)) return identities;462}463/**464 * Performs deep search on collection to find any match to the property and evalutates if truthy465 * @param {Any} collection466 * @param {Property} identity467 * @param {Optional Number} maxDepth468 * @return {boolean} If match confirmed and truthy will return true, otherwise false469 */470function foundTruthy(collection,identity,maxDepth=null){471 identity = singleProperty(identity);472 if(isFalsy(identity)) return undefined;473 function _foundTruthy(collection,identity,maxDepth,currentDepth=0){474 if(containsKeys(collection,[identity])) return isTruthy(collection[identity]);475 if(maxDepth!==null) if(currentDepth >= maxDepth) return false;476 if(isIterable(collection))477 for(var i = 0, keys = Object.keys(collection), l = keys.length; i < l; i++ ){478 const 479 key = keys[i], subcollection = collection[key],480 res = _foundTruthy(subcollection,identity,maxDepth,currentDepth + 1);481 if(res) return true;482 }483 return false;484 }485 return _foundTruthy(collection,identity,maxDepth,0);486}487/**488 * Validates if identity is equal to a property definition or contains a single property key.489 * @param {Property} identity490 * @return {String || boolean} If criteria matched will return property name as string, otherwise false491 */492function singleProperty(identity){493 const propCount = length(identity);494 if(propCount > 1) return false;495 if(propCount===1) return Object.keys(identity)[0]; 496 if(propCount===0) if(['string','number'].indexOf(getType(identity))>-1) return identity;497 return false;498}499/**500 * Determines if identity is non-falsy501 * @param {Any} identity502 * @return {boolean} Returns true if criteria matched, otherwise false.503 */504function isTruthy(identity){ return !isFalsy(identity); }505/**506 * Determines if identity is falsy507 * @param {Any} identity508 * @return {boolean} Returns true if criteria matched, otherwise false.509 */510function isFalsy(identity){511 if(falser(identity)===false) return true;512 return false;513}514/**515 * Converts false-like values into actual boolean value of false516 * @param {Any} identity517 * @return {Any || boolean} Returns false is value is falsy, otherwise returns original value.518 */519function falser(identity){520 if(isIterable(identity)) return identity;521 if(['null','undefined'].indexOf(getType(identity))>-1) return false;522 if(['',0,false].indexOf(identity)>-1) return false;523 return identity;524}525/**526 * Check the length of the top-most depth of the identity527 * @param {Any} identity528 * @return {integer} Greater than or equal to 0.529 */530function length(identity){531 if(['array','object'].indexOf(getType(identity)) === -1) return 0;532 return Object.keys(identity).length;533}534/**535 * Performs deep search for each identity on collection, to shorten the identities to those that does meets the match criteria536 * @param {Any} collection537 * @param {Any} identities538 * @param {Optional Number} maxDepth539 * @return {Any} Returns a collection of the same type as the 'identities' parameter provided with only the identities that were not matched.540 */541function onlyMissing(collection,identities,maxDepth=null){542 if(getType(identities)==='array'){543 let result = [];544 identities.forEach( identity => { 545 if(!exists(collection,identity,maxDepth)) result.push(identity);546 });547 return result;548 }549 if(getType(identities)==='object'){550 let result = {};551 Object.keys(identities).forEach( key => {552 let identity = identities[key]; 553 if(!exists(collection,identity,maxDepth)) result[key] = identity;554 });555 return result;556 }557 if(!exists(collection,identities,maxDepth)) return identities;558}559/**560 * Performs deep search for each identity on collection, to shorten the identities to those that meets the match criteria561 * @param {Any} collection562 * @param {Any} identities563 * @param {Optional Number} maxDepth564 * @return {Any} Returns a collection of the same type as the 'identities' parameter provided with only the identities that matched.565 */566function onlyExisting(collection,identities,maxDepth=null){567 if(getType(identities)==='array'){568 let result = [];569 identities.forEach( identity => { 570 if(exists(collection,identity,maxDepth)) result.push(identity);571 });572 return result;573 }574 if(getType(identities)==='object'){575 let result = {};576 Object.keys(identities).forEach( key => {577 let identity = identities[key]; 578 if(exists(collection,identity,maxDepth)) result[key] = identity;579 });580 return result;581 }582 if(exists(collection,identities,maxDepth)) return identities;583}584/**585 * Performs deep search on collection to find any match to the identity586 * @param {Any} collection587 * @param {Any} identity588 * @param {Optional Number} maxDepth589 * @return {boolean} If a match is confirmed will return true, otherwise false590 */591function exists(collection, identity, maxDepth=null, currentDepth=0){592 if(identical(collection,identity)) return true;593 if(isIterable(identity))594 if(sameType(collection,identity))595 if(containsKeys(collection,Object.keys(identity))){596 const trimmed = trim(collection,Object.keys(identity));597 if(identical(trimmed,identity)) return true;598 }599 if(maxDepth === null ? true: (currentDepth < maxDepth))600 if(isIterable(collection))601 for(var i = 0, keys = Object.keys(collection), l = keys.length; i < l; i++ ){602 const 603 key = keys[i], subcollection = collection[key],604 res = exists(subcollection,identity,maxDepth,currentDepth + 1);605 if(res) return true;606 }607 return false;608}609/**610 * Performs deep search on collection to find all matches to the identity, will return a list of identities containing the match. If no matches found, it returns `undefined`.611 * @param {Any} collection612 * @param {Any} identity613 * @param {Optional Number} maxDepth614 * @return {Array || undefined} identities615 */616function deepFilter(collection, identity, maxDepth=null){617 var paths = locateAll(collection, identity, maxDepth);618 if(paths === false) return undefined;619 const results = paths.map(path => {620 if(path === '') return collection;621 path = path.split('.');622 if(['array','object'].indexOf(getType(identity)) === - 1) path.splice(-1,1);623 var result = collection;624 if(!Array.isArray(path)) return result[path];625 path.forEach( key => { result = result[key]; });626 return result;627 })628 return results;629}630/**631 * Performs deep search on collection to find all matches to the identity, returns a string array containing the location of all matches. If no matches found, it returns `false`.632 * @param {Any} collection633 * @param {Any} identity634 * @param {Optional Number} maxDepth635 * @return {Array || false} Paths636 */637function locateAll(collection, identity, maxDepth=null){638 var R = [];639 function _locateAll(collection, identity, path = '',maxDepth,currentDepth){640 if(isIterable(identity))641 if(sameType(collection,identity))642 if(containsKeys(collection,Object.keys(identity))){643 const trimmed = trim(collection,Object.keys(identity));644 if(identical(trimmed,identity)) R[R.length] = path;645 }646 if(identical(collection,identity)) R[R.length] = path;647 var result = false;648 if(maxDepth!==null)if(currentDepth>=maxDepth) return result;649 if(isIterable(collection))650 for(var i = 0, keys = Object.keys(collection), l = keys.length; i < l; i++ ){651 const key = keys[i], subcollection = collection[key];652 _locateAll(subcollection,identity,(path === '' ? path : path + '.') + key,maxDepth,currentDepth + 1);653 } 654 }655 _locateAll(collection, identity, '', maxDepth, 0);656 return R.length === 0 ? false : R;657}658/**659 * Performs deep search on collection to find a match to the identity, will return the identity containing of the first instance matched. If no matches found, it returns `undefined`.660 * @param {Any} collection661 * @param {Any} identity662 * @param {Optional Number} maxDepth663 * @return {identity || undefined} identity664 */665function deepGet(collection, identity, maxDepth=null){666 var path = locate(collection, identity, maxDepth);667 if(path === false) return undefined;668 if(path === '') return collection;669 path = path.split('.');670 if(['array','object'].indexOf(getType(identity)) === - 1) path.splice(-1,1);671 var result = collection;672 if(!Array.isArray(path)) return result[path];673 path.forEach( key => { result = result[key]; });674 return result;675}676/**677 * Performs deep search on collection to find a match to the identity, will return the path of the first instance matched as string. If no matches found, returns `false`.678 * @param {Any} collection679 * @param {Any} identity680 * @param {Optional number} maxDepth681 * @return {string || false} path682 */683function locate(collection, identity, maxDepth=null){684 function _locate(collection, identity, path = '', maxDepth,currentDepth){685 if(isIterable(identity))686 if(sameType(collection,identity))687 if(containsKeys(collection,Object.keys(identity))){688 const trimmed = trim(collection,Object.keys(identity));689 if(identical(trimmed,identity)) return path;690 }691 if(identical(collection,identity)) return path;692 var result = false;693 if(maxDepth!==null)if(currentDepth>=maxDepth) return result;694 if(isIterable(collection))695 for(var i = 0, keys = Object.keys(collection), l = keys.length; i < l; i++ ){696 const 697 key = keys[i], subcollection = collection[key],698 res = _locate(subcollection,identity,key,maxDepth,currentDepth + 1);699 if(res) { path = path === '' ? path : path + '.'; result = path + res; break; }700 } 701 return result;702 }703 return _locate(collection, identity,'', maxDepth,0);704}705/**706 * Trims an identity to only contain the specified properties.707 * @param {Any} identity708 * @param {Any} keyList709 * @return {Object or Array} Returns , otherwise false710 */711function trim(identity,keyList){712 const identityType = getType(identity);713 if(['array','object'].indexOf(identityType) === -1) return undefined;714 const keyCount = keyList.length;715 if(keyCount === 0) return undefined;716 var newIdentity;717 switch(identityType){718 case 'object' : newIdentity = {}; keyList.forEach(key => { if(key in identity) newIdentity[key] = identity[key]; }); break;719 case 'array' : newIdentity = []; keyList.forEach(key => { if(key in identity) newIdentity.push(identity[key]); }); break;720 }721 return newIdentity;722}723/**724 * Check if identity contains all of the specified keys725 * @param {Any} identity726 * @param {Array} keyList727 * @return {boolean} true || false728 */729function containsKeys(identity,keyList){730 const keyCount = keyList.length;731 if(keyCount === 0 || !isIterable(identity)) return false;732 const identitykeys = Object.keys(identity);733 var result = true;734 for(var i = 0; i < keyCount; i++){735 const key = '' + keyList[i]; 736 if(identitykeys.indexOf(key) === -1){ result = false; break; }737 }738 return result;739}740/**741 * Check if identity has one or more keys to iterate742 * @param {Any} identity743 * @return {boolean} true || false744 */745function isIterable(identity){746 if(['array','object'].indexOf(getType(identity)) === -1) return false;747 if(Object.keys(identity).length === 0) return false;748 return true;749}750/**751 * Compares two identities, will return either true if identical, otherwise false.752 * @param {Any} identityA753 * @param {Any} identityB754 * @return {boolean} true || false755 */756function identical(identityA,identityB){757 const structureMatch = sameStructure(identityA,identityB);758 if(structureMatch === false) return structureMatch;759 if(['array','object'].indexOf(structureMatch) === -1) return identityA === identityB;760 const Keys = Object.keys(identityA), KeyCount = Keys.length;761 var childMatch = true;762 for(var i = 0; i < KeyCount; i++) {763 const Key = Keys[i], identicalMatch = identical(identityA[Key],identityB[Key]);764 if(identicalMatch === false){ childMatch = identicalMatch; break; };765 }766 return childMatch;767}768/**769 * Compares data structure of two identities, will return either the dataType or true/false.770 * @param {Any} identityA771 * @param {Any} identityB772 * @return {String || False} DataType as string for positive match, otherwise false773 */774function sameStructure(identityA,identityB){775 const typeMatch = sameType(identityA,identityB);776 if(typeMatch === false) return false;777 if(['array','object'].indexOf(typeMatch) > -1){778 const 779 AKeys = Object.keys(identityA),780 BKeys = Object.keys(identityB),781 AKeyCount = AKeys.length,782 BKeyCount = BKeys.length;783 if(!(AKeyCount === BKeyCount)) return false;784 if(AKeyCount === 0) return true;785 for (var i = 0; i < AKeyCount; i++) {786 if(AKeys[i] !== BKeys[i]) return false;787 }788 }789 return typeMatch;790}791/**792 * Compares data type of two identities, will dataType if true.793 * @param {Any} identityA794 * @param {Any} identityB795 * @return {boolean} true || false796 */797function sameType(identityA,identityB){ 798 const typeA = getType(identityA); return typeA === getType(identityB) ? typeA : false; 799}800/**801 * Gets data type; makes distintion between object, array, and null.802 * @param {Any} identity803 * @return {String} dataType804 */805function getType(identity) { 806 if(identity === null) return 'null';807 const it = typeof identity;808 if(it === 'object') if(Array.isArray(identity)) return 'array';809 return it;810}811var mitsuketa = {812 getType : function(identity) { return getType(identity); }, 813 sameType : function(identityA,identityB) { return sameType(identityA,identityB); },814 sameStructure : function(identityA,identityB) { return sameStructure(identityA,identityB); },815 identical : function(identityA,identityB) { return identical(identityA,identityB); },816 isIterable : function(identity) { return isIterable(identity); },817 containsKeys : function(identity,keyList) { return containsKeys(identity,keyList); },818 trim : function(identity,keyList) { return trim(identity,keyList); },819 locate : function(collection,identity,maxDepth) { return locate(collection,identity,maxDepth); },820 deepGet : function(collection,identity,maxDepth) { return deepGet(collection,identity,maxDepth); },821 locateAll : function(collection,identity,maxDepth) { return locateAll(collection,identity,maxDepth); },822 deepFilter : function(collection,identity,maxDepth) { return deepFilter(collection,identity,maxDepth); },823 exists : function(collection,identity,maxDepth) { return exists(collection,identity,maxDepth); },824 onlyExisting : function(collection,identities,maxDepth) { return onlyExisting(collection,identities,maxDepth); },825 onlyMissing : function(collection,identities,maxDepth) { return onlyMissing(collection,identities,maxDepth); },826 length : function(identity) { return length(identity); },827 isFalsy : function(identity) { return isFalsy(identity); },828 isTruthy : function(identity) { return isTruthy(identity); },829 foundTruthy : function(collection,identity,maxDepth) { return foundTruthy(collection,identity,maxDepth); },830 onlyTruthy : function(collection,identities,property,maxDepth) { return onlyTruthy(collection,identities,property,maxDepth); },831 foundFalsy : function(collection,identity,maxDepth) { return foundFalsy(collection,identity,maxDepth); },832 onlyFalsy : function(collection,identities,property,maxDepth) { return onlyFalsy(collection,identities,property,maxDepth); },833 countMatches : function(collection,identity,nthDepth,maxDepth) { return countMatches(collection,identity,nthDepth,maxDepth); },834 matchDepth : function(collection,identity,maxDepth) { return matchDepth(collection,identity,maxDepth); },835 maxDepth : function(identity,maxLayer) { return maxDepth(identity,maxLayer); },836 locate_Key : function(collection,keyName,maxDepth) { return locate_Key(collection,keyName,maxDepth); },837 deepGet_Key : function(collection,keyName,maxDepth) { return deepGet_Key(collection,keyName,maxDepth); },838 locateAll_Key : function(collection,keyName,maxDepth) { return locateAll_Key(collection,keyName,maxDepth); },839 deepFilter_Key : function(collection,keyName,maxDepth) { return deepFilter_Key(collection,keyName,maxDepth); },840 deepClone : function(identity,maxDepth,startDepth) { return deepClone(identity,maxDepth,startDepth); },841 renameKey : function(identity,keyName,newKeyName,maxDepth) { return renameKey(identity,keyName,newKeyName,maxDepth); },842 renameKeys : function(identity,keyName,newKeyName,maxDepth) { return renameKeys(identity,keyName,newKeyName,maxDepth); },843 deepRemove_Key : function(identity,keyName,maxDepth) { return deepRemove_Key(identity,keyName,maxDepth); },844 deepRemoveAll_Key : function(identity,keyName,maxDepth) { return deepRemoveAll_Key(identity,keyName,maxDepth); }845}...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

1/*2VT x VC / T / P = SAC3VT... Total Volume of Cylinder in liters4VC... Consumed Volume in Bars during Dive5T... duration of the dive in minutes6D... Depth7P... pressure in bars of average dive8SAC... Surface Air Conspumtion in liters per minutes 9*/10function CalSac(){11 var volumeTotal = document.getElementById("SACVT").value;12 if(!checkIfValid(volumeTotal, "SACVT"))13 return;14 var volumeConsumtion = document.getElementById("SACVC").value;15 if(!checkIfValid(volumeConsumtion, "SACVC"))16 return;17 var time = document.getElementById("SACT").value;18 if(!checkIfValid(time, "SACT"))19 return;20 var depth = document.getElementById("SACD").value;21 if(!checkIfValid(depth, "SACD"))22 return;23 var pressure = (depth / 10) + 1;24 var surfaceAirConsumption = volumeTotal*volumeConsumtion/time/pressure;25 document.getElementById("SacOutput").value = "Your average Surface Air Consumption is "+ surfaceAirConsumption.toFixed(2) +" l/min";26}27function checkIfValid(number, prefix){28 if(isNaN(number))29 {30 alert(number+" is not a number please re-enter");31 document.getElementById(prefix).value = "";32 return 0; 33 }34 return 1;35}36function CalCylinder(){37 var air = document.getElementById("AirConsumption").value;38 if(!checkIfValid(air, "AirConsumption"))39 return;40 var cylinder = air/150;41 document.getElementById("Cylinderout").value = "You need at least a " + cylinder.toFixed(2) +"l cylinder.";42 if(cylinder < 10){43 document.getElementById("Cylinderout").value += "Hence you should get the 10l Cylinder";44 }45 else if(cylinder < 12){46 document.getElementById("Cylinderout").value += "Hence you should get the 12l Cylinder";47 }48 else if(cylinder < 15){49 document.getElementById("Cylinderout").value += "Hence you should get the 15l Cylinder";50 }51 else if(cylinder < 20){52 document.getElementById("Cylinderout").value += "Hence you should get the 20l Cylinder";53 }54}55function showRightInput(){56 var choice = document.getElementById("Calculations").value;57 switch (parseInt(choice)){58 case 1: //SAC59 document.getElementById("SACdiv").style = "visibility: visible";60 document.getElementById("PlanDivediv").style = "visibility: hidden;";61 document.getElementById("Cylinderdiv").style = "visibility: hidden;";62 document.getElementById("HowTodiv").style = "visibility: hidden;";63 break;64 case 2: //PlanDive65 document.getElementById("SACdiv").style = "visibility: hidden;";66 document.getElementById("PlanDivediv").style = "visibility: visible;";67 document.getElementById("Cylinderdiv").style = "visibility: hidden";68 document.getElementById("HowTodiv").style = "visibility: hidden;";69 break;70 case 3: //Cylinder71 document.getElementById("Cylinderdiv").style = "visibility: visible;";72 document.getElementById("SACdiv").style = "visibility: hidden;";73 document.getElementById("PlanDivediv").style = "visibility: hidden;";74 document.getElementById("HowTodiv").style = "visibility: hidden;";75 break;76 case 4:77 document.getElementById("Cylinderdiv").style = "visibility: hidden;";78 document.getElementById("SACdiv").style = "visibility: hidden;";79 document.getElementById("PlanDivediv").style = "visibility: hidden;";80 document.getElementById("HowTodiv").style = "visibility: visible;";81 break;82 }83}84function calOnLoad(){85 hideCalculus();86}87function hideCalculus(){88 document.getElementById("SACdiv").style = "visibility: hidden";89 document.getElementById("PlanDivediv").style = "visibility: hidden";90 document.getElementById("Cylinderdiv").style = "visibility: hidden";91 document.getElementById("canavasDivePlan").style = "visibility: hidden";92}93function CalPlan(){94 var totalAir = 0;95 var bottomTime = document.getElementById("BottomTime").value;96 if(!checkIfValid(bottomTime, "BottomTime"))97 return;98 99 var maxDepth = document.getElementById("PlanDepth").value;100 if(!checkIfValid(maxDepth, "PlanDepth"))101 return;102 103 if(document.getElementById("Brevet1").checked){104 if(maxDepth > 20){105 OutOfRange("For Brevet* there is a max. depth of 20m", "PlanDepth");106 return;107 }108 }109 if(document.getElementById("Brevet2").checked){110 if(maxDepth > 30){111 OutOfRange("For Brevet** there is a max. depth of 30m", "PlanDepth");112 return;113 }114 }115 if(document.getElementById("Brevet3").checked){116 if(maxDepth > 40){117 OutOfRange("For Brevet*** there is a max. depth of 40m", "PlanDepth");118 return;119 }120 }121 var planSAC = document.getElementById("PlanSAC").value;122 if(!checkIfValid(planSAC, "PlanSAC"))123 return;124 //#region DecompressionTable check125 if(maxDepth < 12){126 if(bottomTime > 140){127 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");128 return;129 }130 }131 else if(maxDepth < 15){132 if(bottomTime > 72){133 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");134 return;135 }136 }137 else if(maxDepth < 18){138 if(bottomTime > 45){139 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");140 return;141 }142 }143 else if(maxDepth < 21){144 if(bottomTime > 31){145 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");146 return;147 }148 }149 else if(maxDepth < 24){150 if(bottomTime > 23){151 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");152 return;153 }154 }155 else if(maxDepth < 27){156 if(bottomTime > 18){157 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");158 return;159 }160 }161 else if(maxDepth < 30){162 if(bottomTime > 15){163 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");164 return;165 }166 }167 else if(maxDepth < 33){168 if(bottomTime > 12){169 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");170 return;171 }172 }173 else if(maxDepth < 36){174 if(bottomTime > 10){175 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");176 return;177 }178 }179 else if(maxDepth < 39){180 if(bottomTime > 9){181 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");182 return;183 }184 }185 else if(maxDepth < 42){186 if(bottomTime > 7){187 OutOfRange("As a sportdiver you are not allowed to make decompression dives.","BottomTime");188 return;189 }190 }191 //#endregion192 //#region Calculate totalAir usage193 totalAir += ((maxDepth / 10) + 1) * planSAC * bottomTime; //BottomTime194 totalAir += 3*1.5*planSAC; //5m decostop195 totalAir += (maxDepth/10) * ((maxDepth/10)+1) *planSAC; //emerge196 var totalTime = parseInt(bottomTime,10) + 3 + (maxDepth/10);197 if(maxDepth > 20){198 totalAir += (((maxDepth/2) / 10)+1) * 3 * planSAC;199 totalTime += 3;200 }201 //#endregion202 drawDivePlan(bottomTime,totalTime,maxDepth);203 document.getElementById("Planout").value = "For this "+ Math.ceil(totalTime) +"min. dive you have a total airconsumption of "+Math.round(totalAir)+" l";204}205function drawDivePlan(bottomTime, totalTime, maxDepth){206 var canvas = document.getElementById("canvasDivePlan");207 var graphics = canvas.getContext("2d");208 graphics.font = "12px Arial";209 graphics.moveTo(0,0);210 graphics.lineTo(maxDepth,maxDepth*10);211 //maxdepth212 graphics.moveTo(maxDepth,maxDepth*10);213 var x = parseInt(maxDepth*5,10) + parseInt(bottomTime*20,10);214 graphics.fillText("max depth at "+maxDepth+"m", maxDepth, parseInt(maxDepth*10+10,10));215 graphics.lineTo(x, maxDepth*10);216 graphics.moveTo(x,maxDepth*10);217 if(maxDepth > 20){218 if(maxDepth/2 < 15)219 {220 //smaller221 graphics.lineTo(parseInt(x+(maxDepth/2)) ,(maxDepth/2)*10);222 223 //deep deco224 graphics.fillText("deep safety stop at "+maxDepth/2+"m", parseInt(x+(maxDepth/2)) ,(maxDepth/2)*10+10);225 graphics.moveTo(parseInt(x+(maxDepth/2)) ,(maxDepth/2)*10);226 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 ,(maxDepth/2)*10);227 graphics.moveTo(parseInt(x+(maxDepth/2)) + 10 ,(maxDepth/2)*10);228 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 + 10, 50);229 //small deco230 graphics.fillText("small safety stop at 5m", parseInt(x+(maxDepth/2)) + 10 + 10, 60);231 graphics.moveTo(parseInt(x+(maxDepth/2)) + 10 + 10, 50);232 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 + 10 + 10, 50);233 234 graphics.moveTo(parseInt(x+(maxDepth/2)) + 10 + 10 + 10, 50);235 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 + 10 + 10 + 10, 0);236 }237 else238 {239 //15240 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) ,150);241 //deep deco242 graphics.fillText("deep safety stop at 15m", parseInt(x+(maxDepth-(maxDepth-15))) ,160);243 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) ,150);244 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 ,150);245 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 ,150);246 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 ,50);247 //small deco248 graphics.fillText("small safety stop 5m", parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 ,60);249 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 ,50);250 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 +10 ,50);251 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 +10 ,50);252 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 +10 +10 ,0);253 }254 }255 else{256 graphics.lineTo(x+ parseInt(maxDepth,10), 5*10);257 //small deco258 graphics.fillText("small safety stop 5m", x+ parseInt(maxDepth,10),60);259 graphics.moveTo(x+ parseInt(maxDepth,10), 5*10);260 graphics.lineTo(x+ parseInt(maxDepth,10) + parseInt(10,10), 5*10);261 262 graphics.moveTo(x+ parseInt(maxDepth,10) + parseInt(10,10), 5*10);263 graphics.lineTo(x+ parseInt(maxDepth,10) + parseInt(10,10) + parseInt(10,10), 0);264 265 266 }267 graphics.stroke();268}269function OutOfRange(message, prefix){270 alert(message);271 document.getElementById(prefix).value = ""; ...

Full Screen

Full Screen

draw.js

Source:draw.js Github

copy

Full Screen

1function drawDivePlan(bottomTime, totalTime, maxDepth){2 var canvas = document.getElementById("canvasDivePlan");3 var graphics = canvas.getContext("2d");4 graphics.font = "12px Arial";5 graphics.moveTo(0,0);6 graphics.lineTo(maxDepth,maxDepth*10);7 //maxdepth8 graphics.moveTo(maxDepth,maxDepth*10);9 var x = parseInt(maxDepth*5,10) + parseInt(bottomTime*20,10);10 graphics.fillText("max depth at "+maxDepth+"m", maxDepth, parseInt(maxDepth*10+10,10));11 graphics.lineTo(x, maxDepth*10);12 graphics.moveTo(x,maxDepth*10);13 if(maxDepth > 20){14 if(maxDepth/2 < 15)15 {16 //smaller17 graphics.lineTo(parseInt(x+(maxDepth/2)) ,(maxDepth/2)*10);18 19 //deep deco20 graphics.fillText("deep safety stop at "+maxDepth/2+"m", parseInt(x+(maxDepth/2)) ,(maxDepth/2)*10+10);21 graphics.moveTo(parseInt(x+(maxDepth/2)) ,(maxDepth/2)*10);22 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 ,(maxDepth/2)*10);23 graphics.moveTo(parseInt(x+(maxDepth/2)) + 10 ,(maxDepth/2)*10);24 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 + 10, 50);25 //small deco26 graphics.fillText("small safety stop at 5m", parseInt(x+(maxDepth/2)) + 10 + 10, 60);27 graphics.moveTo(parseInt(x+(maxDepth/2)) + 10 + 10, 50);28 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 + 10 + 10, 50);29 30 graphics.moveTo(parseInt(x+(maxDepth/2)) + 10 + 10 + 10, 50);31 graphics.lineTo(parseInt(x+(maxDepth/2)) + 10 + 10 + 10 + 10, 0);32 }33 else34 {35 //1536 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) ,150);37 //deep deco38 graphics.fillText("deep safety stop at 15m", parseInt(x+(maxDepth-(maxDepth-15))) ,160);39 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) ,150);40 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 ,150);41 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 ,150);42 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 ,50);43 //small deco44 graphics.fillText("small safety stop 5m", parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 ,60);45 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 ,50);46 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 +10 ,50);47 graphics.moveTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 +10 ,50);48 graphics.lineTo(parseInt(x+(maxDepth-(maxDepth-15))) + 10 + 10 +10 +10 ,0);49 }50 }51 else{52 graphics.lineTo(x+ parseInt(maxDepth,10), 5*10);53 //small deco54 graphics.fillText("small safety stop 5m", x+ parseInt(maxDepth,10),60);55 graphics.moveTo(x+ parseInt(maxDepth,10), 5*10);56 graphics.lineTo(x+ parseInt(maxDepth,10) + parseInt(10,10), 5*10);57 58 graphics.moveTo(x+ parseInt(maxDepth,10) + parseInt(10,10), 5*10);59 graphics.lineTo(x+ parseInt(maxDepth,10) + parseInt(10,10) + parseInt(10,10), 0);60 61 62 }63 graphics.stroke();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = new Tree();2var node1 = new Node(1);3var node2 = new Node(2);4var node3 = new Node(3);5var node4 = new Node(4);6var node5 = new Node(5);7var node6 = new Node(6);8var node7 = new Node(7);9var node8 = new Node(8);10var node9 = new Node(9);11var node10 = new Node(10);12var node11 = new Node(11);13var node12 = new Node(12);14var node13 = new Node(13);15var node14 = new Node(14);16var node15 = new Node(15);17var node16 = new Node(16);18var node17 = new Node(17);19var node18 = new Node(18);20var node19 = new Node(19);21var node20 = new Node(20);22var node21 = new Node(21);23var node22 = new Node(22);24var node23 = new Node(23);25var node24 = new Node(24);26var node25 = new Node(25);27var node26 = new Node(26);28var node27 = new Node(27);29var node28 = new Node(28);30var node29 = new Node(29);31var node30 = new Node(30);32var node31 = new Node(31);33var node32 = new Node(32);34var node33 = new Node(33);35var node34 = new Node(34);36var node35 = new Node(35);37var node36 = new Node(36);38var node37 = new Node(37);39var node38 = new Node(38);40var node39 = new Node(39);41var node40 = new Node(40);42var node41 = new Node(41);43var node42 = new Node(42);44var node43 = new Node(43);45var node44 = new Node(44);46var node45 = new Node(45);47var node46 = new Node(46);48var node47 = new Node(47);49var node48 = new Node(48);50var node49 = new Node(49);51var node50 = new Node(50);52var node51 = new Node(51);53var node52 = new Node(52);54var node53 = new Node(53);55var node54 = new Node(54);

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log(maxDepth(0));2console.log(maxDepth(1));3console.log(maxDepth(2));4console.log(maxDepth(3));5console.log(maxDepth(4));6console.log(maxDepth(5));7console.log(maxDepth(6));8console.log(maxDepth(7));9console.log(maxDepth(8));10console.log(maxDepth(9));11console.log(maxDepth(10));12console.log(maxDepth(11));13console.log(maxDepth(12));14console.log(maxDepth(13));15console.log(maxDepth(14));16console.log(maxDepth(15));17console.log(maxDepth(16));18console.log(maxDepth(17));19console.log(maxDepth(18));20console.log(maxDepth(19));21console.log(maxDepth(20));22console.log(maxDepth(21));23console.log(maxDepth(22));24console.log(maxDepth(23));25console.log(maxDepth(24));26console.log(maxDepth(25));27console.log(maxDepth(26));28console.log(maxDepth(27));29console.log(maxDepth(28));30console.log(maxDepth(29));31console.log(maxDepth(30));32console.log(maxDepth(31));33console.log(maxDepth(32));34console.log(maxDepth(33));35console.log(maxDepth(34));36console.log(maxDepth(35));37console.log(maxDepth(36));38console.log(maxDepth(37));39console.log(maxDepth(38));40console.log(maxDepth(39));41console.log(maxDepth(40));42console.log(maxDepth(41));43console.log(maxDepth(42));44console.log(maxDepth(43));45console.log(maxDepth(44));46console.log(maxDepth(45));47console.log(maxDepth(46));48console.log(maxDepth(47));49console.log(maxDepth(48));50console.log(maxDepth(49));51console.log(maxDepth(50));52console.log(maxDepth(51));53console.log(maxDepth(52));54console.log(maxDepth(53));55console.log(maxDepth(54));56console.log(maxDepth(55));57console.log(maxDepth(56));58console.log(maxDepth(57));59console.log(maxDepth(58));60console.log(maxDepth(59));61console.log(maxDepth(60));62console.log(maxDepth(61));63console.log(maxDepth(62));64console.log(maxDepth(63));65console.log(maxDepth(64));66console.log(maxDepth(65));67console.log(maxDepth(66));68console.log(maxDepth(67));69console.log(maxDepth(68));70console.log(maxDepth(69));71console.log(maxDepth(70));

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = Tree();2tree.addChild(5);3tree.addChild(6);4tree.addChild(7);5tree.children[0].addChild(8);6tree.children[0].addChild(9);7tree.children[0].children[0].addChild(10);8tree.children[0].children[0].addChild(11);9tree.children[2].addChild(12);10tree.children[2].addChild(13);11tree.children[2].children[0].addChild(14);12tree.children[2].children[0].addChild(15);13console.log(tree.maxDepth());14var tree = Tree();15tree.addChild(5);16tree.addChild(6);17tree.addChild(7);18tree.children[0].addChild(8);19tree.children[0].addChild(9);20tree.children[0].children[0].addChild(10);21tree.children[0].children[0].addChild(11);22tree.children[2].addChild(12);23tree.children[2].addChild(13);24tree.children[2].children[0].addChild(14);25tree.children[2].children[0].addChild(15);26console.log(tree.isBalanced());27var tree = Tree();28tree.addChild(5);29tree.addChild(6);30tree.addChild(7);31tree.children[0].addChild(8);32tree.children[0].addChild(9);33tree.children[0].children[0].addChild(10);34tree.children[0].children[0].addChild(11);35tree.children[2].addChild(12);36tree.children[2].addChild(13);37tree.children[2].children[0].addChild(14);38tree.children[2].children[0].addChild(15);39tree.children[2].children[0].children[0].addChild(16);40tree.children[2].children[0].children[0].addChild(17);41tree.children[2].children[0].children[0].children[0].addChild(18);42tree.children[2].children[0].children[0].children[0].addChild(19);43tree.children[2].children[0].children[0].children[0].children[0].addChild(20);

Full Screen

Using AI Code Generation

copy

Full Screen

1let tree = new Tree();2tree.insert(5);3tree.insert(3);4tree.insert(7);5tree.insert(1);6tree.insert(4);7tree.insert(6);8tree.insert(8);9tree.insert(9);10tree.insert(10);11tree.insert(11);12tree.insert(12);13tree.insert(13);14tree.insert(14);15tree.insert(15);16tree.insert(16);17tree.insert(17);18tree.insert(18);19tree.insert(19);20tree.insert(20);21tree.insert(21);22tree.insert(22);23tree.insert(23);24tree.insert(24);25tree.insert(25);26tree.insert(26);27tree.insert(27);28tree.insert(28);29tree.insert(29);30tree.insert(30);31tree.insert(31);32tree.insert(32);33tree.insert(33);34tree.insert(34);35tree.insert(35);36tree.insert(36);37tree.insert(37);38tree.insert(38);39tree.insert(39);40tree.insert(40);41tree.insert(41);42tree.insert(42);43tree.insert(43);44tree.insert(44);45tree.insert(45);46tree.insert(46);47tree.insert(47);48tree.insert(48);49tree.insert(49);50tree.insert(50);51tree.insert(51);52tree.insert(52);53tree.insert(53);54tree.insert(54);55tree.insert(55);56tree.insert(56);57tree.insert(57);58tree.insert(58);59tree.insert(59);60tree.insert(60);61tree.insert(61);62tree.insert(62);63tree.insert(63);64tree.insert(64);65tree.insert(65);66tree.insert(66);67tree.insert(67);68tree.insert(68);69tree.insert(69);70tree.insert(70);71tree.insert(71);72tree.insert(72);73tree.insert(73);74tree.insert(74);75tree.insert(75);76tree.insert(76);77tree.insert(77);78tree.insert(78);79tree.insert(79);80tree.insert(80);81tree.insert(81);82tree.insert(82);83tree.insert(83);84tree.insert(84);85tree.insert(85);86tree.insert(86);87tree.insert(87);88tree.insert(88);89tree.insert(89);90tree.insert(90);91tree.insert(91);92tree.insert(92);93tree.insert(93);94tree.insert(94);95tree.insert(95);96tree.insert(96);97tree.insert(97);98tree.insert(98);99tree.insert(99);

Full Screen

Using AI Code Generation

copy

Full Screen

1var Tree = require('./tree.js');2var tree = new Tree();3tree.add(3);4tree.add(2);5tree.add(4);6tree.add(1);7tree.add(5);8console.log(tree.maxDepth());

Full Screen

Using AI Code Generation

copy

Full Screen

1var avatar = require("./avatar.js");2var maxDepth = avatar.maxDepth;3console.log(maxDepth([1, 2, 3, [4, 5, [6, 7, [8, 9]]]]));4console.log(maxDepth([1, 2, 3, [4, 5, [6, 7, [8, 9]]], 10]));5console.log(maxDepth([1, 2, 3, [4, 5, [6, 7, [8, 9]]], 10, [11, 12]]));6var avatar = require("./avatar.js");7var sum = avatar.sum;8console.log(sum([1, 2, 3, 4, 5]));9console.log(sum([6, 7, 8]));10console.log(sum([10]));11console.log(sum([-5, 100]));12var avatar = require("./avatar.js");13var count = avatar.count;14console.log(count([1, 2, 3, 4, 5]));15console.log(count([6, 7, 8]));16console.log(count([10]));17console.log(count([-5, 100]));18var avatar = require("./avatar.js");19var average = avatar.average;20console.log(average([1, 2, 3, 4, 5]));21console.log(average([6, 7, 8]));22console.log(average([10]));23console.log(average([-5, 100]));

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = new availableTree();2tree.addValue(5);3tree.addValue(3);4tree.addValue(7);5tree.addValue(1);6tree.addValue(6);7tree.addValue(8);8tree.addValue(9);9tree.addValue(10);10tree.addValue(11);11tree.addValue(12);12tree.addValue(13);13tree.addValue(14);14tree.addValue(15);15tree.addValue(16);16tree.addValue(17);17tree.addValue(18);18tree.addValue(19);19tree.addValue(20);20tree.addValue(21);21tree.addValue(22);22tree.addValue(23);23tree.addValue(24);24tree.addValue(25);25tree.addValue(26);26tree.addValue(27);27tree.addValue(28);28tree.addValue(29);29tree.addValue(30);30tree.addValue(31);31tree.addValue(32);32tree.addValue(33);33tree.addValue(34);34tree.addValue(35);35tree.addValue(36);36tree.addValue(37);37tree.addValue(38);38tree.addValue(39);39tree.addValue(40);40tree.addValue(41);41tree.addValue(42);42tree.addValue(43);43tree.addValue(44);44tree.addValue(45);45tree.addValue(46);46tree.addValue(47);47tree.addValue(48);48tree.addValue(49);49tree.addValue(50);50tree.addValue(51);51tree.addValue(52);52tree.addValue(53);53tree.addValue(54);54tree.addValue(55);55tree.addValue(56);56tree.addValue(57);57tree.addValue(58);58tree.addValue(59);59tree.addValue(60);60tree.addValue(61);61tree.addValue(62);62tree.addValue(63);63tree.addValue(64);64tree.addValue(65);65tree.addValue(66);66tree.addValue(67);67tree.addValue(68);68tree.addValue(69);69tree.addValue(70);70tree.addValue(71);71tree.addValue(72);72tree.addValue(73);73tree.addValue(74);74tree.addValue(75);75tree.addValue(76);76tree.addValue(77);77tree.addValue(78);78tree.addValue(79);79tree.addValue(80);80tree.addValue(81);81tree.addValue(82);82tree.addValue(83);83tree.addValue(84);84tree.addValue(85);85tree.addValue(86);86tree.addValue(87);87tree.addValue(88);88tree.addValue(89);89tree.addValue(90);90tree.addValue(91);91tree.addValue(92);92tree.addValue(93);93tree.addValue(94);94tree.addValue(95);95tree.addValue(96);96tree.addValue(97);97tree.addValue(98

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful