-
[알고리즘/자바스크립트] 문자열 카운터 (String incrementer)Algorithm 2019. 8. 4. 23:00
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- String incrementer Your job is to write a function which increments a string, to create a new string. If the string already ends with a number, the number should be incremented by 1. If the string does not end with a number. the number 1 should be appended to the new string. foo → foo1 foobar23 → foobar24 foo0042 → foo0043 foo9 → foo10 ..
-
[알고리즘/자바스크립트] Pig Latin 게임 (Simple Pig Latin)Algorithm 2019. 8. 4. 22:32
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Simple Pig Latin Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched. pigIt('Pig latin is cool'); // igPay atinlay siay oolcay pigIt('Hello world !'); // elloHay orldway ! 매우 간단한 문제이다. 어떤 문장을 받으면 각 단어의 첫 글자를 그 단어 맨 뒤에 붙이고 'ay'를 덧붙여야한다. ?나 !와 같은 punctuation marks는 제..
-
[알고리즘/자바스크립트] 아나그램 모두 찾기 (Where my anagrams at?)Algorithm 2019. 8. 4. 22:22
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Where my anagrams at? What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example: 'abba' & 'baab' == true 'abba' & 'bbaa' == true 'abba' & 'abbba' == false 'abba' & 'abca' == false Write a function that will find all the anagrams of a word from a list. You will be given two inputs a..
-
[알고리즘/자바스크립트] 반복되지 않는 첫 알파벳 찾기 (First non-repeating character)Algorithm 2019. 8. 4. 22:09
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- First non-repeating character Write a function named first_non_repeating_letter that takes a string input, and returns the first character that is not repeated anywhere in the string. For example, if given the input 'stress', the function should return 't', since the letter t only occurs once in the string, and occurs first in the strin..
-
[알고리즘/자바스크립트] 알파벳 스크램블 (Scramblies)Algorithm 2019. 8. 3. 22:09
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Scramblies Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false. Only lower case letters will be used (a-z). No punctuation or digits will be included. Performance needs to be considered. scramble('rkqodlw', 'world'); // ==> True scramble('c..
-
[알고리즘/자바스크립트] 더해서 특정 숫자가 나오는 한 쌍 찾기 (Sum of Pairs)Algorithm 2019. 6. 11. 19:52
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Given a list of integers and a single sum value, return the first two values (parse from the left please) in order of appearance that add up to form the sum. sum_pairs([11, 3, 7, 5], 10) # ^--^ 3 + 7 = 10 == [3, 7] sum_pairs([4, 3, 2, 3, 4], 6) # ^-----^ 4 + 2 = 6, indices: 0, 2 * # ^-----^ 3 + 3 = 6, indices: 1, 3 # ^-----^ 2 + 4 ..
-
[알고리즘/자바스크립트] 함수로 계산하기 (Calculating with Functions)Algorithm 2019. 4. 29. 15:03
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] This time we want to write calculations using functions and get the results. Let's have a look at some examples: JavaScript: seven(times(five())); // must return 35 four(plus(nine())); // must return 13 eight(minus(three())); // must return 5 six(dividedBy(two())); // must return 3 Ruby: seven(times(five)) # must return 35 four(plu..
-
[알고리즘/자바스크립트] 연속하는 숫자의 합 중 가장 큰 값 구하기 (Maximum subarray sum)Algorithm 2019. 4. 28. 23:18
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers: maxSequence([-2, 1, -3, 4, -1, 2, 1, -5, 4]) // should be 6: [4, -1, 2, 1] Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of the whole array. If the list is..
-
[알고리즘/자바스크립트] 배열에서 반대 방향 제거하기 (Directions Reduction)Algorithm 2019. 4. 9. 22:44
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Once upon a time, on a way through the old wild west,… … a man was given directions to go from one point to another. The directions were "NORTH", "SOUTH", "WEST", "EAST". Clearly "NORTH" and "SOUTH" are opposite, "WEST" and "EAST" too. Going to one direction and coming back the opposite direction is a needless effort. Since this is..
-
[알고리즘/자바스크립트] 초를 시:분:초 형태로 변환하기 (Human Readable Time)Algorithm 2019. 4. 5. 22:38
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS) HH = hours, padded to 2 digits, range: 00 - 99 MM = minutes, padded to 2 digits, range: 00 - 59 SS = seconds, padded to 2 digits, range: 00 - 59 The maximum time never exceeds 359999 (99:59:59) You can ..