Last active
July 21, 2019 06:56
-
-
Save luisenriquecorona/2b30b64be85e901ef8359ed20c9efd6d to your computer and use it in GitHub Desktop.
ES6
This file contains hidden or 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
//The codePointAt() Method | |
let text = "𠮷"; | |
console.log(text.length); | |
console.log(/^.$/.test(text)); | |
console.log(text.charAt(0)); | |
console.log(text.charAt(1)); | |
console.log(text.charCodeAt(0)); | |
console.log(text.charCodeAt(1)); | |
let text = "𠮷a"; | |
console.log(text.charCodeAt(0)); | |
console.log(text.charCodeAt(1)); | |
console.log(text.charCodeAt(2)); | |
console.log(text.codePointAt(0)); | |
console.log(text.codePointAt(1)); | |
console.log(text.codePointAt(2)); | |
function is32Bit(c) { | |
return c.codePointAt(0) > 0xFFFF; | |
} | |
console.log(is32Bit("𠮷")); // true | |
console.log(is32Bit("a")); // false | |
//The String.fromCodePoint() Method | |
console.log(String.fromCodePoint(134071)); // "𠮷" | |
//The u Flag in Action | |
let text = "𠮷"; | |
console.log(text.length); | |
console.log(/^.$/.test(text)); | |
console.log(/^.$/u.test(text)); | |
//Counting Code Points | |
function codePointLength(text) { | |
let result = text.match(/[\s\S]/gu); | |
return result ? result.length : 0; | |
} | |
console.log(codePointLength("abc")); // 3 | |
console.log(codePointLength("𠮷bc")); // 3 | |
//Methods for Identifying Substrings | |
let msg = "Hello world!"; | |
console.log(msg.startsWith("Hello")); | |
console.log(msg.endsWith("!")); | |
console.log(msg.includes("o")); | |
console.log(msg.startsWith("o")); | |
console.log(msg.endsWith("world!")); | |
console.log(msg.includes("x")); | |
console.log(msg.startsWith("o", 4)); | |
console.log(msg.endsWith("o", 8)); | |
console.log(msg.includes("o", 8)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment