31 - Sequences And Series CodeWars Kata (6 Kyu)

Add reaction Like Unicorn Exploding Head Raised Hands Fire Jump to Comments Save Boost More... Copy link Copy link Copied to Clipboard Share to X Share to LinkedIn Share to Facebook Share to Mastodon Share Post via... Report Abuse 1 #1 - Points of reflection (8 kyu) Codewars Kata 2 #2 - Hamming Distance CodeWars Kata (6 kyu) ... 43 more parts... 3 #3 - Wilson primes CodeWars Kata (8 kyu) 4 #4 - Pair of gloves CodeWars Kata (6 kyu) 5 #5 - People in the Bus CodeWars Kata (6 kyu) 6 #6 - Incrementer CodeWars Kata (7 kyu) 7 #7 - Closest and Smallest CodeWars Kata (5 kyu) 8 #8 - Simple remove duplicates CodeWars Kata (7 kyu) 9 #9 - Twin Prime CodeWars Kata (6 kyu) 10 #10 - Valid Spacing CodeWars Kata (7 kyu) 11 #11 - Vowel remover CodeWars Kata (8 kyu) 12 #12 - Fibonacci digit sequence CodeWars Kata (6 kyu) 13 #13 - Keypad Horror CodeWars Kata (7 kyu) 14 #14 - Keypad Horror CodeWars Kata (7 kyu) 15 #15 - Digits explosion CodeWars Kata (7 kyu) 16 #16 - Sums of parts CodeWars Kata (6 kyu) 17 #17 - The highest profit wins! CodeWars Kata (7 kyu) 18 #18 - Previous multiple of three CodeWars Kata (7 kyu) 19 #19 - Binary Addition CodeWars Kata (7 kyu) 20 #20 - Sort Numbers CodeWars Kata (7 kyu) 21 #21 - Sum of integers in string CodeWars Kata (7 kyu) 22 #22 - Find the unique number CodeWars Kata (6 kyu) 23 #23 - Change it up CodeWars Kata (6 kyu) 24 #24 - Create Phone Number CodeWars Kata (6 kyu) 25 #25 - Remove consecutive duplicate words CodeWars Kata (7 kyu) 26 #26 - Pillars CodeWars Kata (8 kyu) 27 #27 - Your order, please CodeWars Kata (6 kyu) 28 #28 - Sum of two lowest positive integers - CodeWars Kata (7 kyu) 29 #29 - Ones' Complement CodeWars Kata (7 kyu) 30 #30 - Multiplication table CodeWars Kata (6 kyu) 31 #31 - Sequences and Series CodeWars Kata (6 kyu) 32 #32 - Find the divisors! CodeWars Kata (7 kyu) 33 #33 -Derivatives of type x^n - CodeWars Kata (6 kyu) 34 #34 -Shortest code: Bug in Apple - CodeWars Kata (6 kyu) 35 #35 -(Ready for) Prime Time - CodeWars Kata (5 kyu) 36 #36 - Sum of Multiples CodeWars Kata (8 kyu) 37 #37 - Row of the odd triangle - CodeWars Kata (6 kyu) 38 #38 - Assemble string CodeWars Kata (6 kyu) 39 #39 - Two Sum CodeWars Kata (6 kyu) 40 #40 - Credit Card Mask Kata (7 kyu) 41 #41 - Split Strings Codewars Kata (6 kyu) 42 #42 - How many pages in a book? - Codewars Kata (6 kyu) 43 #43 - If you can read this... - Codewars Kata (6 kyu) 44 How can you help? 45 #44 - Where is my parent!?(cry) - Codewars Kata (6 kyu) 46 #45 - Persistent Bugger - Codewars Kata (6 kyu) 47 #46 - Sum of a sequence - Codewars Kata (7 kyu)

Instructions

Have a look at the following numbers.

n score
1 50
2 150
3 300
4 500
5 750

Can you find a pattern in it? If so, then write a function getScore(n)/get_score(n)/GetScore(n) which returns the score for any positive number n.

Note Real test cases consists of 100 random cases where 1 <= n <= 10000

My solution:

function getScore(n) { let r = 0; for(let i = 1; i<=n; i++){ r += i*50 } return r } Enter fullscreen mode Exit fullscreen mode

Explanation

First I had to identify the pattern, I saw that every score is equal to the sum of each number by 50, I did a for loop that iterated until "i" is equal to "n", and in each iteration I summed the "r" actual value plus the result of "i" by 50, that way I can get the last result.

let r = 0; for(let i = 1; i<=n; i++){ r += i*50 }

at the end of the for loop I just returned "r"

return r

What do you think about this solution? 👇🤔

My Github My twitter Solve this Kata

1 #1 - Points of reflection (8 kyu) Codewars Kata 2 #2 - Hamming Distance CodeWars Kata (6 kyu) ... 43 more parts... 3 #3 - Wilson primes CodeWars Kata (8 kyu) 4 #4 - Pair of gloves CodeWars Kata (6 kyu) 5 #5 - People in the Bus CodeWars Kata (6 kyu) 6 #6 - Incrementer CodeWars Kata (7 kyu) 7 #7 - Closest and Smallest CodeWars Kata (5 kyu) 8 #8 - Simple remove duplicates CodeWars Kata (7 kyu) 9 #9 - Twin Prime CodeWars Kata (6 kyu) 10 #10 - Valid Spacing CodeWars Kata (7 kyu) 11 #11 - Vowel remover CodeWars Kata (8 kyu) 12 #12 - Fibonacci digit sequence CodeWars Kata (6 kyu) 13 #13 - Keypad Horror CodeWars Kata (7 kyu) 14 #14 - Keypad Horror CodeWars Kata (7 kyu) 15 #15 - Digits explosion CodeWars Kata (7 kyu) 16 #16 - Sums of parts CodeWars Kata (6 kyu) 17 #17 - The highest profit wins! CodeWars Kata (7 kyu) 18 #18 - Previous multiple of three CodeWars Kata (7 kyu) 19 #19 - Binary Addition CodeWars Kata (7 kyu) 20 #20 - Sort Numbers CodeWars Kata (7 kyu) 21 #21 - Sum of integers in string CodeWars Kata (7 kyu) 22 #22 - Find the unique number CodeWars Kata (6 kyu) 23 #23 - Change it up CodeWars Kata (6 kyu) 24 #24 - Create Phone Number CodeWars Kata (6 kyu) 25 #25 - Remove consecutive duplicate words CodeWars Kata (7 kyu) 26 #26 - Pillars CodeWars Kata (8 kyu) 27 #27 - Your order, please CodeWars Kata (6 kyu) 28 #28 - Sum of two lowest positive integers - CodeWars Kata (7 kyu) 29 #29 - Ones' Complement CodeWars Kata (7 kyu) 30 #30 - Multiplication table CodeWars Kata (6 kyu) 31 #31 - Sequences and Series CodeWars Kata (6 kyu) 32 #32 - Find the divisors! CodeWars Kata (7 kyu) 33 #33 -Derivatives of type x^n - CodeWars Kata (6 kyu) 34 #34 -Shortest code: Bug in Apple - CodeWars Kata (6 kyu) 35 #35 -(Ready for) Prime Time - CodeWars Kata (5 kyu) 36 #36 - Sum of Multiples CodeWars Kata (8 kyu) 37 #37 - Row of the odd triangle - CodeWars Kata (6 kyu) 38 #38 - Assemble string CodeWars Kata (6 kyu) 39 #39 - Two Sum CodeWars Kata (6 kyu) 40 #40 - Credit Card Mask Kata (7 kyu) 41 #41 - Split Strings Codewars Kata (6 kyu) 42 #42 - How many pages in a book? - Codewars Kata (6 kyu) 43 #43 - If you can read this... - Codewars Kata (6 kyu) 44 How can you help? 45 #44 - Where is my parent!?(cry) - Codewars Kata (6 kyu) 46 #45 - Persistent Bugger - Codewars Kata (6 kyu) 47 #46 - Sum of a sequence - Codewars Kata (7 kyu) pic Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Submit Preview Dismiss Code of Conduct Report abuse

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.

Hide child comments as well

Confirm

For further actions, you may consider blocking this person and/or reporting abuse

Cesar Del rio Follow Join me on my road to mastering coding. 100 days of codewars challenge.
  • Location México
  • Work CEO at Mercurio Agencia Digital
  • Joined Dec 29, 2021
#46 - Sum of a sequence - Codewars Kata (7 kyu) #javascript #programming #100daysofcode #computerscience Any advice for Google STEP program? #beginners #programming #javascript #motivation #45 - Persistent Bugger - Codewars Kata (6 kyu) #javascript #programming #100daysofcode #computerscience
DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

Tag » Codewars 6 Kyu Solutions