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
| extern crate rand; | |
| use rand::Rng; | |
| fn main() { | |
| let n = rand::thread_rng().gen_range(1, 91); | |
| match n { | |
| n if n >= 1 && n <= 10 => { | |
| println!("大吉"); | |
| } |
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
| extern crate rand; | |
| use rand::Rng; | |
| fn main() { | |
| println!("おみくじだよ!"); | |
| let secret_num = rand::thread_rng().gen_range(0, 7); | |
| match secret_num { |
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
| function validAnagram(str1, str2) { | |
| if (typeof str1 === 'string' && typeof str2 === 'string') { | |
| if (str1.length !== str2.length) { | |
| return false; | |
| } | |
| const counter1 = {}; | |
| const counter2 = {}; | |
| for (let ch of str1) { | |
| counter1[ch] = (counter1[ch] || 0) + 1; | |
| } |
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
| function same(arr1, arr2) { | |
| // O(N) | |
| if (Array.isArray(arr1) && Array.isArray(arr2)) { | |
| if (arr1.length !== arr2.length) { | |
| return false; | |
| } | |
| const freqCounter1 = {}; | |
| const freqCounter2 = {}; | |
| for (let val of arr1) { | |
| freqCounter1[val] = (freqCounter1[val] || 0) + 1; |
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
| function same(arr1, arr2) { | |
| if (Array.isArray(arr1) && Array.isArray(arr2)) { | |
| for (let i = 0; i < arr1.length; i++) { | |
| if (!arr2.includes(arr1[i] * arr1[i])) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| return false; |
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
| function reverse(str) { | |
| if (typeof str === "string") { | |
| return str.split("").reduce((a, b) => { | |
| return b + a; | |
| }); | |
| } | |
| } |
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
| function reverseStr3(str) { | |
| let reversed = ""; | |
| for (let char of str) { | |
| reversed = char + reversed; | |
| } | |
| return reversed; | |
| } |
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
| function reverseStr2(str) { | |
| const arr = str.split(""); | |
| for (let i = 0; i < Math.floor(str.length / 2); i++) { | |
| let temp = arr[i]; | |
| arr[i] = arr[str.length - i]; | |
| arr[str.length - i] = temp; | |
| } | |
| return arr.join(""); | |
| } |
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
| function reverseStr(str) { | |
| if (typeof str === "string") { | |
| return str | |
| .split("") | |
| .reverse() | |
| .join(); | |
| } | |
| } |
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
| function falsyBouncer(arr) { | |
| if (Array.isArray(arr)) { | |
| return arr.filter(val => { | |
| return !!val; | |
| }); | |
| } | |
| } |
NewerOlder