-
[알고리즘/자바스크립트] 두 객체를 비교하여 케이크 만들 수 있는 최대 횟수 구하기 (Pete, the baker)Algorithm 2019. 2. 24. 20:40
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Pete likes to bake some cakes. He has some recipes and ingredients. Unfortunately he is not good in maths. Can you help him to find out, how many cakes he could bake considering his recipes? Write a function cakes(), which takes the recipe (object) and the available ingredients (also an object) and returns the maximum number of cak..
-
[알고리즘/자바스크립트] 배열의 특정요소만 맨 뒤로 옮기기 (Moving Zeros To The End)Algorithm 2019. 2. 24. 14:25
-해당 문제는 codewars사이트의 level5 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0] [해석] 배열에 있는 모든 0을 맨 뒤로 옮기되, 다른 요소들의 위치는 변경시키면 안된다. 레벨5 라고는 하지만 내 생각엔 레벨6~7 정도 되는 쉬운 문제인 것 같다.배열에서 0만 맨 뒤로 옮겨서 출력하는 문제! var moveZeros = func..
-
[알고리즘/자바스크립트] 어떤 값의 개수가 홀수인지 판별하기 (Find the odd int)Algorithm 2019. 2. 24. 12:17
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Given an array, find the int that appears an odd number of times.There will always be only one integer that appears an odd number of times. findOdd([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]) ==> 5 출력findOdd([1,1,2,-2,5,2,4,4,-1,-2,5]) ==> -1 출력 [해석] 어떤 배열이 주어졌을 때 홀수번 등장하는 숫자를 구하여라. 홀수번 등장하는 숫자는 딱 하나만 있을것이다.예를 들어서 [20,1,-1,2,-2,3,3,..
-
[알고리즘/자바스크립트] 트리보나치 수열 구하기 (Tribonacci Sequence)Algorithm 2019. 2. 20. 22:02
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :( So, if we are t..
-
[알고리즘/자바스크립트] 홀수 짝수 판별하여 map()으로 배열 재구성하기 (WeIrD StRiNg CaSe)Algorithm 2019. 2. 19. 22:28
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Write a function toWeirdCase (weirdcase in Ruby) that accepts a string, and returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased. The indexing just explained is zero based, so the zero-ith index is even, therefore that character should be upper ca..
-
[알고리즘/자바스크립트] 삼각형 판별문제 (Is this a triangle?)Algorithm 2019. 2. 18. 21:55
-해당 문제는 codewars사이트의 level7 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Implement a method that accepts 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of given length and false in any other case. (In this case, all triangles must have surface greater than 0 to be accepted). Test.describe("PublicTest", function() { Test.assertEquals(isTriangle(1,2,2), t..
-
[알고리즘/자바스크립트] 완벽한 제곱근 구하기 (Find the next perfect square!)Algorithm 2019. 2. 18. 00:08
-해당 문제는 codewars사이트의 level7 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] You might know some pretty large perfect squares. But what about the NEXT one? Complete the findNextSquare method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n such that sqrt(n) is also an integer. If the parameter is itself not a perfect squa..
-
[알고리즘/자바스크립트] 마지막 4글자 제외하고 #으로 치환하기 (Credit Card Mask)Algorithm 2019. 2. 17. 22:53
-해당 문제는 codewars사이트의 level7 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it. Your task is to write a function maskify, which changes all but the ..
-
[알고리즘/자바스크립트] 특정문자 공백으로 치환해서 return하기 (Dubstep)Algorithm 2019. 2. 17. 13:26
-해당 문제는 codewars사이트의 level6 문제입니다.(1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words (that don't contain WUB). To make the dubstep remix of this song, Polycarpus ..
-
[알고리즘/자바스크립트] 최소값 구하기 / 단어 중 가장 길이가 짧은 단어의 length를 구하기 (Shortest Word)Algorithm 2019. 2. 17. 11:59
-해당 문제는 codewars사이트의 level7 문제입니다.(1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Simple, given a string of words, return the length of the shortest word(s).String will never be empty and you do not need to account for different data types. Test.describe("Example tests",_=>{Test.assertEquals(findShort("bitcoin take over the world maybe who knows perhaps"), 3);Test.assertEquals(findShort("turns out random test cas..