-
[알고리즘/자바스크립트] 한 자리수가 될 때까지 곱하기 (Persistent Bugger)Algorithm 2019. 8. 3. 21:40
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- Persistent Bugger Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit. For example: persistence(39) === 3 // because 3*9 = 27, 2*7 = 14, 1*4=4 // and 4 has only one digit persisten..
-
[알고리즘/자바스크립트] 섬 개수 세기 (Island Count)Algorithm 2019. 6. 22. 11:43
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Given a string representation of a 2d map, return the number of islands in the map. Land spaces are denoted by a zero. Water is denoted by a dot. Rows are denoted by newlines ('\n'). Two land spaces are considered connected if they are adjacent (horizontal or vertical, but not diagonal). Too easy? Try solving it without recursion....
-
[알고리즘/자바스크립트] 재귀를 이용한 "음이 아닌 정수의 자릿수근" 구하기 (Sum of Digits / Digital Root)Algorithm 2019. 6. 8. 22:33
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] In this kata, you must create a digital root function. A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers. Here's how ..
-
[알고리즘/자바스크립트] 재귀를 이용한 배열 요소 개수 구하기 (Array Deep Count)Algorithm 2019. 6. 7. 23:56
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Array.prototype.length will give you the number of top-level elements in an array. Your task is to create a function deepCount that returns the number of ALL elements within an array, including any within inner-level arrays. deepCount([1, 2, 3]); //>>>>> 3 deepCount(["x", "y", ["z"]]); //>>>>> 4 deepCount([1, 2, [3, 4, [5]]]); //>>..
-
[알고리즘/자바스크립트] 괄호 짝 찾기 (Valid Braces)Algorithm 2019. 5. 3. 17:28
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] 괄호들로 이루어진 string을 입력받아서, 괄호들의 순서가 올바른지 판단해주는 함수를 완성해주세요! 괄호들은 ()와 {}와 [], 이렇게 총 3가지 종류가 있습니다. 괄호들은 자기와 짝이 맞는 괄호를 만나야만 합니다. 다음의 예를 봐주세요, validBraces("(){}[]") // => True validBraces("([{}])") // => True validBraces("(}") // => False validBraces("[(])") // => False validBraces("[({})](]") // => False * @param {string} braces * @retur..
-
[알고리즘/자바스크립트] 트리보나치, 피보나치 수열 "재귀함수"로 구하기 (Fibonacci, Tribonacci Sequence)Algorithm 2019. 4. 15. 00:28
[알고리즘/자바스크립트] 트리보나치 수열 구하기 (Tribonacci Sequence) -해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basicall.. im-developer.tistory.com 2개월 전에 풀었던 알고리즘 문제를 "재귀함수"를 이용해서 풀어보았다. 지난번에는 위 링크를 보면 알겠지만 function tribonacci (signature, n) { if(n
-
[알고리즘/자바스크립트] 배열의 값으로 수량 체크하기 (Help the bookseller!)Algorithm 2019. 3. 3. 21:31
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] A bookseller has lots of books classified in 26 categories labeled A, B, ... Z. Each book has a code c of 3, 4, 5 or more capitals letters. The 1st letter of a code is the capital letter of the book category. In the bookseller's stocklist each code c is followed by a space and by a positive integer n (int n >= 0) which indicates th..
-
[알고리즘/자바스크립트] 배열에 요소 추가하고 합치기 (Create Phone Number)Algorithm 2019. 2. 24. 21:05
-해당 문제는 codewars사이트의 level6 문제입니다. (1~8단계 중 8단계가 가장 쉬운 레벨)- [문제] Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number. Example:createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890" The returned format must be correct in order to complete this challenge. Don't forget the space after..
-
[알고리즘/자바스크립트] 어떤 값의 개수가 홀수인지 판별하기 (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..