Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meine loesungen #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

meine loesungen #1

wants to merge 2 commits into from

Conversation

marcorensch
Copy link

quick and dirty

Marco Rensch added 2 commits April 2, 2022 17:00
let quersumme = 0;
for(let n of zahlen){
if(n > 9){
n = n+"" // String daraus machen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etwas weniger hacky String(n)

for (const nstring of stringArr) {
numVal += parseInt(nstring)
}
numVal = stringArr[0] === '-' ? numVal * -1 : numVal;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hast du das ganze mal mit -94 getestet ;)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw n < 0 wäre eine alternative, gell?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hast du das ganze mal mit -94 getestet ;)?

jap ist mir danach auch eingefallen :-)

let zeichenkette = "Ich bin eine Zeichenkette"
{
// Neu:
let alternative = zeichenkette => zeichenkette.split('').map((c,i) => i & 1 ? c.toUpperCase() : c.toLowerCase()).join('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i & 1 ist nice und würde im code golf wohl gegen i % 2 gewinnen. ich persönlich finde aber i%2 schneller verständlich, bzw. sprechender.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants