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
//Example 4 | |
const arr = ['a', 'b']; | |
// Validate that an array literal will have the 'Array.prototype' object | |
// as its immediate parent in the prototype chain which in turn will have | |
// as its prototype 'Object.prototype' which is the last link in the chain | |
console.log(arr.__proto__ === Array.prototype); // true | |
console.log(Array.prototype.__proto__ === Object.prototype); // true | |
// Validate that 'Object.prototype' is the last link in the prototype chain as |
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
//Example 3 | |
const arr = ['a', 'b']; | |
// Arrays have a type of 'object' and in addition to the | |
// explicitly declared properties and values, it can also access | |
// built-in methods through inheritance along its prototype chain | |
console.log(typeof arr); // 'object' | |
console.log(arr[0]); // 'a' | |
console.log(arr[1]); // 'b' | |
console.log(arr.join('')); // 'ab' |
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
// Example 2 | |
// create new function 'func' | |
const func = function() { | |
console.log('hello world!'); | |
}; | |
// Validate that the [[Prototype]] of the function object 'func' is 'Function.prototype' | |
// which is the base object from which all other functions inherit. The 'constructor' | |
// property of 'func' simply points back to the 'Function' constructor. | |
console.log(func.__proto__ === Function.prototype); // true |
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
// Example 1 | |
const obj = { | |
color: "blue", | |
amount: 100, | |
}; | |
// Check the type of the object literal 'obj' | |
console.log(typeof obj); // 'object' | |
// Verify that 'obj' has the properties we expect it to have |
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 nextBiggerNum(inputNum) { | |
let newNum = inputNum + 1; | |
let initLen = String(inputNum).length; | |
while (String(newNum).length <= initLen) { | |
if (sameDigits(inputNum, newNum)) { | |
return newNum; | |
} | |
newNum += 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
function nextBiggerNum(num) { | |
let validNumsArr = getValidNums(num); | |
let validNumsSorted = getSortedUniqueNums(validNumsArr); | |
let numIdx = validNumsSorted.indexOf(String(num)); | |
// check if largest possible num | |
if (numIdx === validNumsSorted.length - 1) return -1; | |
// if not largest, return next bigger num |