This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sortedTemps = temps.sort((a, b) => Math.abs(a) - Math.abs(b) || b - a); | |
const result = sortedTemps[0] || 0; | |
console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart | |
console.log('10'.padStart(2, '0')); // expected output: "10" | |
console.log('9'.padStart(2, '0')); // expected output: "09" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flattenArray = (arr) => { | |
return arr.reduce((a, v) => { | |
return a.concat(Array.isArray(v) ? flattenArray(v) : v) | |
}, []); | |
} | |
// ESLint.com | |
// https://eslint.org/demo#eyJ0ZXh0IjoiY29uc3QgZmxhdHRlbkFycmF5ID0gKGFycikgPT4ge1xuICByZXR1cm4gYXJyLnJlZHVjZSgoYWNjdSwgY3VycikgPT4ge1xuICAgIHJldHVybiBhLmNvbmNhdChBcnJheS5pc0FycmF5KGN1cnIpID8gZmxhdHRlbkFycmF5KGN1cnIpIDogY3VycilcbiAgfSwgW10pO1xufSIsIm9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hVmVyc2lvbiI6Nywic291cmNlVHlwZSI6InNjcmlwdCIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6e30sImVudiI6eyJicm93c2VyIjp0cnVlLCJub2RlIjp0cnVlLCJjb21tb25qcyI6dHJ1ZSwic2hhcmVkLW5vZGUtYnJvd3NlciI6dHJ1ZSwid29ya2VyIjp0cnVlLCJhbWQiOnRydWUsIm1vY2hhIjp0cnVlLCJqYXNtaW5lIjp0cnVlLCJqZXN0Ijp0cnVlLCJwaGFudG9tanMiOnRydWUsImpxdWVyeSI6dHJ1ZSwicXVuaXQiOnRydWUsInByb3RvdHlwZWpzIjp0cnVlLCJzaGVsbGpzIjp0cnVlLCJtZXRlb3IiOnRydWUsIm1vbmdvIjp0cnVlLCJwcm90cmFjdG9yIjp0cnVlLCJhcHBsZXNjcmlwdCI6dHJ1ZSwibmFzaG9ybiI6dHJ1ZSwic2VydmljZXdvcmtlciI6dHJ1ZSwiYXRvbXRlc3QiOnRydWUsImVtYmVydGVzdCI6dHJ1ZSwid2ViZXh0ZW5zaW9ucyI6dHJ1ZS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//uitls.js : CREATE NAMESPACING functions also use ‘define()’ to declare it as requirjs module | |
(function (requirejs) { | |
define('utils', function () { | |
// Allow creation of methods for SHOP modules | |
window.UTILS = window.UTILS || {}; | |
var u = window.UTILS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Function declaration | |
function foo() { | |
console.log(arguments); | |
} | |
foo(['a', 'b', 'c'], [1, 2, 3, 4, 5]); | |
//IIFE | |
(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* USAGE: | |
* markdown, gist, github, json, embed | |
* Reference the script in index.html (or main md html file e.g. mdwiki.html) | |
* Then in any .md document include like below. Ensure empty lines before <div> and after </div> | |
* | |
* <div class="gistEmbed" data-gist-id="12265cd979f0dee75acd"></div> | |
* | |
* | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void enhancedForLoop(){ | |
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
System.out.println("\nEXAMPLE: Enhanced For Statement"); | |
for (int temp: arr){ // Create a temporary variable, same type as array values. For | |
// loop assign array value to the temporary variable | |
System.out.println("Enhanced = " + temp); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void witchStatment(int num) { | |
System.out.println("\nEXAMPLE: Switch Statement"); | |
switch(num){ //Check the value | |
case 0: | |
System.out.println("Case = " + num); // Execute this if 'case' matches the 'value' | |
break; // Stop the statement | |
case 1: | |
System.out.println("Case = " + num); // Execute this if 'case' matches the 'value' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void doWhileLoop() { | |
System.out.println("\nEXAMPLE: Do While Loop"); | |
int num = 0; | |
do { | |
// DO the work... Execute the loop first | |
System.out.println("num = " + num); | |
num++; //increment 'l' by 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void whileLoop(){ | |
System.out.println("\nEXAMPLE: While Loop"); | |
int num = 0; | |
while(num <= 20) { // Check the while condition first, Then execute the loop | |
// Then while 'l' is less than or equal to '0' | |
System.out.println("num = " + num); | |
num++; //increment 'l' by 1 |
NewerOlder