Can someone explain how people get this gud...

can someone explain how people get this gud? im doing codewars and the top "clever" solutions just seem impossible to come up with. i mean how does someone even understand something like pic related? (it checks if a string is an isogram)

how do i /into/ this level? is it actually possible or do you just have to be an autist?
>inb4 javascript

Attached: Screen Shot 2018-09-09 at 22.52.32.png (494x136, 16K)

Other urls found in this thread:

regex101.com/
twitter.com/NSFWRedditGif

>he doesn't even have a CS degree

just some pretty noddy pattern matching m8

learn perl it's not difficult

Looks like regex to me, or am I missing something here?

It's just regex.

>i know regex OP!!!! yes i DO!! AND... ITS NOT HARD AT ALL!!!! xDDD
>4 posts in 3 seconds

kill yourselves, retarded little nerds

All this is doing is taking the input string (str) and testing it against a regex that looks for a single word character that appears at any point between it and the rest of the input in a case-insensitive manner. If it's found, it returns the opposite of that.

>being this mad at not knowing regex

This is a terrible solution. Regex with backreferences possibly lead to exponential runtime.
This can easily be done by
return new Set(str.split('')).size === s;

which not only runs faster, but is more easily understood.

>didn't know shit from week 2 of CS101
>get buttmad when people point it out
Ok

>can someone explain how people get this gud?
experience

>top "clever" solutions
not really useful outside coding challenges

real world code should be easy to read and modify by anybody

i know regex and im not OP you retarded fucking nigger

im just pointing out the joy in a nerds soul when something he gets used to gets mentioned as "hard". Nerds are disgusting creatures and should get slaughtered to death.

cheeky pattern matching, probably no more efficient than keeping tracking of seen letters with a hashtable under the hood though

Just read the Wikipedia page on regular expressions.

It's not complicated, but it does take some practice to get used to it.

It's a regex. A finite state machine. A subset of turing machines. You're literally worse than a fucking turing machine.

Regex with backreferences cannot be implemented with a finite state machine. Kys idiot.

What is "s" here?

You definitely don’t if you’re that triggered to post this. I’m not a full time dev and don’t find example anything special. Kid clearly is a student and nerds are saying “invest 3 hours and you’ll understand this too”.

function isIsogram(s) {
return new Set(s.split('')).size === s;
}

no they dont idiotic subhuman filth

they are saying "ive memorized useless dumb shit used in production code SOLELY for email verification and nothing else and thats why im smart!!!"

regex is useless shit for basement dwellers

die you idiotic fucking neet imbecil

isIsogram('Hello');
false
isIsogram('Helo');
false

Attached: torvalds.jpg (442x293, 13K)

function isIsogram(s) {
return new Set(s.split('')).size === s.size;
}

you tried

Attached: thumbsup.jpg (251x231, 7K)

I think you mean:
...=== s.length;

yeah fuck this
function FUCK(s) {
return new Set(s.split('')).size === s.length;
}

Still returns false for "Helo"

Oh you’re a front end “engineer” lol got it hey man you’re smart too congrats on maxing out at 80k a year that’s enough to buy a jet ski!

That particular language is regular though, since the backreferenced segment is of bounded length.

see

Ok but now it's not case insensitive like in OP's image

meant for

It's seriously not a difficult regex if you think about the problem

isogram is a word with 1 repeated letter, so you do a check to see if any letter has the same letter later on in the word

if it does, it isn't an isogram

(\w) is a letter captured due to ()
.* means 0 or more letters
\1 means the first captured group
lastly ! means not

the i at the end btw means case-insentive afaik

Please tell us what you do for a living so we can all have a good chuckle over a 6 pack of Monsters

function g(s) {
return new Set(s.toLowerCase().split('')).size === s.length;
}

>*OP asks question*
>*people answer*
>*assblasted virgin barges into the thread to complain about people knowing regex*
>*gets called out*
>"k-k-kill yourself!"
log out

I largely agree but the regular expression method does more: it checks for word characters and compensates for case.

Those extra features could easily be added to your method though.

developer advocate for game evangelists at a small start up

\w is a word character that includes numbers and underscores. .* means 0 or more characters, not specifically letters

nothing really

i shit out REST apis and iphone apps like a pajeet

i dont give a flying fuck about programming, im in it for the money and im making more than you stupid neet faggot nigger

> im in it for the money

sad af
what do you do in your free time/hoobies?

My bad, I knew but for some reason in my head, assumed it was all letters

Ok but now it's not called isIsogram so it can't be swapped out with OP's code

unironically this is the obvious way to do it

>if i call him a virgin theyll never guess that im the virgin!!

theres no log out function on Jow Forums idiotic dweeby moron

You probably have it down mentally already. I'm just being pedantic because I've been bitten by my own regex before

couldn't care less

Good job writing four posts with examples of unusable code

Sounds like a fulfilling existence. Why are you posting on a technology board again?

And I doubt it lol I live in SF I make more than your entire zip code bruddah

living life

unlike you

enjoy writing monad macros and jerking off to tranny porn for the rest of your life fucking freak

i'm not the same you guy you're replying too

>living life
i bet

wouldnt something like this work
function isogram(str) {
return str[0] == str[strlen(str)-1];
}

Are you too scared to smoke weed so smoke that weird legal stuff and have empty beer cans on the shelf of your parents basement

So to recap, it says:

Find any "word character" (letter, number or underscore) which gets repeated anywhere down the string. (So "Fuck!!!!!" is not a match but "fuck off!" is)
I do not care about case (so "Bob" is a match).
Return true if no such match was found, else return false.

>mad lisp/julia/haskell virgin incels projecting their shitty lives on me

swift chads dont have time for virgins.

im gonna fuck my gf now, incels. Take care.

lel, get rekt

function isIsogram(s) {
return new Set(s.split('')).size !== s.length;
}

function getRandomString(vocab, length, isogram = true) {
let auxVocab = vocab.slice();
let picked = [];
if (isogram) {
for (let j = 0; j < length-1; j++) {
picked.push(auxVocab[Math.floor(Math.random() * auxVocab.length)]);
}
picked.push(picked[0]);
}
else {
for (let j = 0; j < length; j++) {
picked.push(auxVocab.splice(Math.floor(Math.random() * auxVocab.length), 1)[0]);
}
}
return picked;
}

function test(vocab, length) {
for (let i = 0; i < 100000; ++i) {
if (isIsogram(getRandomString(vocab, length, false).join(''))) {
console.error("False positive.");
}
}
for (let i = 0; i < 100000; ++i) {
if (!isIsogram(getRandomString(vocab, length, true).join(''))) {
console.error("False negative.");
}
}
}

test('abcdefghijklmnopqrstuvwxyz'.split(''), 10);

For testing purposes. Terribly inefficient but w/e, sue me

sour fucking grapes

yeah pretty much

Properly handles unicode:
function isIsogram(s) {
var map, str, c, i, l, e, h;
if (typeof s !== "string") return false;
if ((l = s.length) < 2) return true;
c = (str = s.toLowerCase()).codePointAt();
if ((h = c > 0xFFFF) && l < 4) return true;
(map = {})[c] = true, e = l - 2, i = h ? 1 : 0;
do {
if (map[c = str.codePointAt(++i)]) return false;
if (c > 0xFFFF) if (i === e) return true; else ++i;
map[c] = true;
} while (i < l);
return true;
}

OP here. i had never heard of regex. thanks for pointin it out frens. here was my solution btw
function isIsogram(str){
const newStr = str.toLowerCase();
const arr = newStr.split("");
let letters = [];
for (let i = 0; i < arr.length; i++) {
if (letters.indexOf(arr[i]) !== -1) {
return false;
}
letters.push(arr[i]);
}
return true;
}


after i saw the solution in the OP pic, i was just left feeling like a faggot for writing ~15 lines in what could have been done in 3. based on these replies, regex isnt actually any more efficient than my code? its just syntactic sugar?

No.
You have to check all characters, not just the first and last.

ie:
"Isogram" is an isogram. (each letter is unique)
"No isogram" is no isogram. (`o` occurs twice)

That's a normal feeling. I've used C for 5 years, did a programming challenge in Python after 2 months practice, and saw my code being written in 3 times less lines, cause of what is actually sensical language constructs like lambdas, rather than the usual unreadable 1-liners

kek saw this a few weeks ago

There are only two good solutions for this.
1. Make a hash set of characters you've already seen. bail and return false if something is already in the set.
This is O(n) best case, might degrade to something like O(n log n) if the hash map implementation sucks at choosing a good size.

2. Make an array of booleans, for each character, set use the character value as an index for the array, set that index to true, returning false if it was already true.
This is O(n) guaranteed but worse for memory efficiency.

The regex does essentially the same thing, yes.
It's probably faster due to optimizations, but there are also more efficient ways than your code. ("indexOf" is very slow)

Even if you choose not to use regular expressions in your code it's still a valuable thing to learn.
Some command line tools (like grep) can use regular expressions.
And some text editors (like Sublime text) can do a find-and-replace based on regular expressions.
Both can be extremely useful sometimes and save you shitloads of work.

>chads
>developing iOS apps natively

You almost had me

regex is read only.

OBVIOUSLY I MEANT WRITE ONLY

Regex expressions are usually a very efficient solution when used correctly. In OP image backtracking can create issues. For short words it probably is more efficient but it can bite you in the ass if you drop a large one.
user's solution is pretty nice as it leverages Set objects which naturally drop any duplicate values.
I am not JS dev but this seems to me the best way someone can do it.

This is actually faster:
function isIsogram(str) {
return new Set(str.toLowerCase()).size === str.length;
}
isIsogram with Set x 1,059,095 ops/sec ±0.44% (88 runs sampled)
isIsogram x 666,490 ops/sec ±1.04% (94 runs sampled)
Fastest is isIsogram with Set
but it obviously does not work in environments where Set is not available

>handles unicode:
Which raises the question:
How does one check for Unicode word characters using regular expressions?

all these pajeets creating sets and wasting memory. I'd do sort + adjacent_find and not touch the heap at all.

All the chars you know can be represented in Unicode

>I'd do sort
wut u doin lad

>environments where Set is not available
damn

You must allocate new memory one way or the other because strings are immutable in JS

>sort

ahhahahahah

rajesh pls

function isIsogram(str) {
return Array.from(str).map((c1,i1,a) => a.map((c2,i2) => i1!=i2 && c1===c2).some(c=>c)).some(c=>c);
}

Are there dynamic arrays? Copy the string, sort and adjacent find. Creating a set is still more expensive.

>I am not JS dev but this seems to me the best way someone can do it.

I think Set() is pretty efficient in JS.
But with large strings that solution does end up making a large Set which I suspect will be slower than checking for duplicates sooner.

Maybe process the string in chunks, returning as soon as one chunk contains a duplicate character (the likelihood of that should be pretty high if the chunks are long enough)
And only if none of the chunks contain any duplicate characters combine the sets into larger and larger sets.

isSetIsogram x 1,046,974 ops/sec ±0.51% (92 runs sampled)
isIsogram x 655,609 ops/sec ±1.13% (91 runs sampled)
isIsogram with sort and find x 509,137 ops/sec ±1.25% (95 runs sampled)
isIsogram with arrays, maps and somes x 178,202 ops/sec ±0.22% (96 runs sampled)

Fastest is isSetIsogram

That's pretty horrible tbhfam

Something like this?
function isSortIsogram(str) {
const chars = [...str.toLowerCase()];
chars.sort();
const len = chars.length - 1;
let i = 0;
while (i < len) if (chars[i] === chars[++i]) return false;
return true;
}
Well see above and you'll see the results

>(\w).*\1

Lemme explain it to you
"(\w)" is to match any word-character. which is the same as a-z, A-Z, and 0-9.

".*" is to match an amount(zero or more) characters of any type. The "." means "any character"(except for newline) and the "*" means "Zero or more"

"\1" is a back-reference, that references the whatever matched the "(\w)" from earlier

So basically, this full regex expression only matches strings that have repeated characters. So it won't match "fou" but it will match "foo" because it will match "o" for "(\w)" and it will find another "o" immediately after using the \1.

So first it detects if there are any characters that repeat, which is the opposite of an isogram. Then it inverses the rest result. So it will first find if there are any repeating characters, and then invert this result to find out if it is an isogram.

Use this tool to test out your regex expression as it explains your regex expression in plain english

regex101.com/

I mean I want to differentiate between Unicode characters that may occur in words, and crap like currency symbols, mathematical symbols, arrows, emoji's, etc.

Could be for a name field where I'd allow Chinese names but not nigger names like Ty$

Actually, made a mistake there by going out of bounds of the array at the end
function isSortIsogram(str) {
const chars = [...str.toLowerCase()];
const len = chars.length;
if (len < 2) return true;
chars.sort();
const end = chars.length - 2;
let i = 0, c = chars[i];
do if (c === (c = chars[++i])) return false;
while (i < end);
return true;
}
Didn't change much regarding performance tho

>retarded opinions not based in fact or reasonable argument
>r*ddit spacing
Please stop LARP'ing on Jow Forums, no one finds you interesting or funny and you can't get upboats here. Leave you disgusting piece of shit

Interesting, what input sizes where you testing?
Given that the JS reference for sort doesn't even specify complexity, I'm not that surprised.

UR NOT FUNNYYYYYY LEAVEEE PLEASSE!!!! :(((

die you fucking basedeating bitch

Attached: unknown.png (991x994, 55K)

So anons how will you do in your language?
Posting the Master Foo way.
isIsogram () {
test `echo $1 | grep -o . | sort -f | uniq -id` && echo 'false' || echo 'true'
}

Why so angry, user? Kindly please back up your statements with reasonable arguments so we can make fun of you more sir, thank you

You will either waste memory or speed.
You cannot have both.

what notepad ++ theme

>does not work in environments where Set is not available
Isn't Set a part of the language? How cannot be available?

Are you benchmarking with a single input? Wouldn't that be prone to caching?

If you using IE8.

Nobody does this

Who uses Internet Explorer at all?

Enterprise companies.

Waher

String literals get interned anyway, doesn't change anything really and we are measuring the functions' runtime anyway

fuck me these solutions are terrible
1. If string length > 256, return false
2. Else, return len(set(str)) == len(str)
Early exit will likely slow you down for small inputs (