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 scramble(str1, str2) { | |
| const charCount = str1 | |
| .split("") | |
| .reduce((a, c) => { | |
| a[c] = (a[c] || 0) + 1 | |
| return a | |
| }, {}) | |
| for(let char of str2) { | |
| if(!charCount[char]) | |
| 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
| verify(/[c]a[rt]/, | |
| ["my car", "bad cats"], | |
| ["camper", "high art"]); | |
| verify(/pr?op/, | |
| ["pop culture", "mad props"], | |
| ["plop", "prrrop"]); | |
| verify(/e?rr+?[eay]/, | |
| ["ferret", "ferry", "ferrari"], |
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
| let number = /^([+-.]?\d+|\d+[+-.]|\d+[.]\d+|\d[.]?\d*[eE][-+]?\d+)$/ | |
| // Tests: | |
| for (let str of ["1", "-1", "+15", "1.55", ".5", "5.", | |
| "1.3e2", "1E-4", "1e+12"]) { | |
| if (!number.test(str)) { | |
| console.log(`Failed to match '${str}'`); | |
| } | |
| } | |
| for (let str of ["1a", "+-1", "1.2.3", "1+1", "1e4.5", |
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
| using System; | |
| class Program { | |
| static void Main(string[] args) { | |
| string result; | |
| string userInput = Console.ReadLine(); | |
| result = ReserveStringAnotherWay(userInput); | |
| Console.WriteLine(result); |
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
| select | |
| c.country_name, | |
| string_agg(a.city, ', ') as city_list | |
| from address a | |
| inner join country c on a.country_id = c.country_id | |
| group by c.country_name; |
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
| create table test_data ( | |
| code_num integer, | |
| code_text text, | |
| code_datetime timestamp with time zone | |
| ); | |
| create or replace procedure generate_data_samples( | |
| in number_of_rows integer | |
| ) | |
| language plpgsql |
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
| class Group { | |
| constructor(arr) { | |
| this.data = {} | |
| this.it = [] | |
| this.pivot = -1 | |
| for(let i of arr) { | |
| this.data[i] = i | |
| } | |
| this.it = Object.values(this.data) // expensive, same data (diff structure) | |
| } |
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
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "net/http" | |
| "time" | |
| ) | |
| func main() { |
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
| func ToInt(str string) int { | |
| // 48 it's representation of the zero in ASCII table, the digits starts in this count | |
| // challenge: https://dev.to/zanfranceschi/desafio-low-level-toint-function-19hk | |
| var integer int | |
| validNumber, _ := regexp.Compile("[0-9]+") | |
| // new string only with digits | |
| justDigits := validNumber.FindString(str) | |
| // length of the slices only with digits | |
| n := len(justDigits) |
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
| package main | |
| import "fmt" | |
| type IPAddr [4]byte | |
| func (ip IPAddr) String() string { | |
| return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]) | |
| } |