728x90
반응형
[자바스크립트로 구현한 알고리즘] List Filtering 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] List Filtering

In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out. Example filter_list([1,2,'a','b']) == [1,2] filter_list([1,'a','b',0,15]) == [1,0,15] filter_list([1,2,'aasf','1','123',123]) == [1,2,123] 필자답안 map을 사용하긴 했지만, 뭔가 2%부족한 답안입니다. 제가 원했던건 map을 사용해서 type이 number라면 그 값만 나오게 하는 것이었는데 number가 아닌 값들은 모두 undef..

2016.10.19 게시됨

[자바스크립트로 구현한 알고리즘] Sum of the first nth term of Series 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Sum of the first nth term of Series

Description: Task: Your task is to write a function which returns the sum of following series upto nth term(parameter). Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +... Rules:· You need to round the answer upto 2 decimal places and return it as String.· If the given value is 0 then it should return 0.00· You will only be given Natural Numbers as arguments. Examples: SeriesSum(1) => 1 = "1" Series..

2016.10.19 게시됨

[자바스크립트로 구현한 알고리즘]  Two to One 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Two to One

Description:Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2.Examples:a = "xyaabbbccccdefww"b = "xxxxyyyyabklmopq"longest(a, b) -> "abcdefklmopqwxy" a = "abcdefghijklmnopqrstuvwxyz"longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" 필자답안 처음에 split() 메소드를 활용해서 문자열 데이터타..

2016.10.19 게시됨

[자바스크립트로 구현한 알고리즘] Sum of two lowest positive integers 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Sum of two lowest positive integers

Description: Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 integers. No floats or empty arrays will be passed. For example, when an array is passed like [19,5,42,2,77], the output should be 7. [10,343445353,3453445,3453545353453] should return 3453455. Hint: Do not modify the original array. 전과 비슷한 문제입니다. 이번 문제는 배열에서 가장 낮은 숫자 2개를 구해서 그 숫자 2..

2016.10.16 게시됨

[자바스크립트로 구현한 알고리즘] Largest Elements 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Largest Elements

Write a program that outputs the top n elements from a list. Example: largest(2, [7,6,5,4,3,2,1]) // => [6,7] 배열의 정렬 메소드와 slice() 메소드를 활용해서 배열에서 제일 큰 값 n개를 뽑아내는 알고리즘입니다.정렬메소드는 문자열 기준으로 동작하므로 숫자를 배열하려면 비교함수를 인자로 넣어줘야되는데요return a - b 를 하면 오름차순return b - a 를 하면 내림차순으로 적용됩니다.

2016.10.16 게시됨

[자바스크립트로 구현한 알고리즘] Fizz / Buzz 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Fizz / Buzz

Description: Write a function that takes an integer and returns an Array [A, B, C] where A is the number of multiples of 3 (but not 5) less than the given integer, B is the number of multiples of 5 (but not 3) less than the given integer and C is the number of multiples of 3 and 5 less than the given integer. For example, solution(20) should return [5, 2, 1] 3의 배수와 5의 배수 그리고 3과 5의 배수가 동시에 충족시키는 ..

2016.10.16 게시됨

[자바스크립트로 구현한 알고리즘] Sum of odd numbers 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Sum of odd numbers

Given the triangle of consecutive odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... Calculate the row sums of this triangle from the row index (starting at index 1) e.g.: rowSumOddNumbers(1); // 1 rowSumOddNumbers(2); // 3 + 5 = 8 너무 어렵게 생각했다..조금만 더 쉽게 생각했으면 훨씬 쉬운 방법을 생각해낼 수 있었는데..간단하게 바로 생각할 수 있는 문제해결능력을 키우도록 노력해야겠다. 왜 이방법을 생각을 못했을꼬...

2016.10.14 게시됨

[자바스크립트로 구현한 알고리즘] Remove the minimum 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Remove the minimum

Description: The museum of incredible dull things The museum of incredible dull things wants to get rid of some exhibitions. Miriam, the interior architect, comes up with a plan to remove the most boring exhibitions. She gives them a rating, and then removes the one with the lowest rating. However, just as she finished rating all exhibitions, she's off to an important fair, so she asks you to wr..

2016.10.14 게시됨

[자바스크립트로 구현한 알고리즘] IQ Test 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] IQ Test

Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is different in evenness, and return a position of this number. ! Keep in mind that you..

2016.09.21 게시됨

[자바스크립트로 구현한 알고리즘] Find the next perfect square! 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Find the next perfect square!

Description: 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 square, than -1 should be returned. You may assume the p..

2016.09.21 게시됨

[자바스크립트로 구현한 알고리즘] Isograms 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Isograms

Description: An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. isIsogram( "Dermatoglyphics" ) == true isIsogram( "aba" ) == false isIsogram( "moOse" ) == false // -- ignore letter case 같은 문자가 나오면 false를 return..

2016.09.20 게시됨

[자바스크립트로 구현한 알고리즘] Credit Card Mask 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Credit Card Mask

Description: 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 last four characters into '#'. Examples maskify("455..

2016.09.20 게시됨

[자바스크립트로 구현한 알고리즘] Descending Order 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Descending Order

Description:Your task is to make a function that can take any non-negative integer as a argument and return it with it's digits in descending order. Descending order means that you take the highest digit and place the next highest digit immediately after it.Examples:Input: 145263 Output: 654321Input: 1254859723 Output: 9875543221 Number 데이터 타입을 String 데이터 타입으로 변환 후 배열로 정렬하고 내림차순으로 정렬한 다음 다시 Numb..

2016.09.20 게시됨

[자바스크립트로 구현한 알고리즘] Vowel Count 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Vowel Count

Description:Return the number (count) of vowels in the given string.We will consider a, e, i, o, and u as vowels for this Kata. 모음을 체크하는 로직을 간단하게 구현했다. 아직은 허접하기 그지없는 코드다.좀 더 개발자답게 코드를 개선해보면 아래와 같다. 매우 간단하지 않은가?이와 같이 코드의 가독성과 효율성까지 생각하면서 짤 수 있는 개발자가 될 수 있도록 노력해야겠다. 참고로 /[aeiou]/ 와 같은 경우는 정규표현식으로 aeiou 중 1개가 포함되는지 체크해주는 것이다. 뒤에 ig의 경우 대문자/소문자를 구별하지 않게 해주는 수식어다.

2016.09.19 게시됨

[자바스크립트로 구현한 알고리즘] Mumbling 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Mumbling

Description:This time no story, no theory. The examples below show you how to write function accum: Examples:accum("abcd"); // "A-Bb-Ccc-Dddd"accum("RqaEzty"); // "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"accum("cwAt"); // "C-Ww-Aaa-Tttt" The parameter of accum is a string which includes only letters from a..z and A..Z. 제가 작성한 코드보다 아래 코드가 훨씬 가독성이 좋은 모범 사례입니다.

2016.09.19 게시됨

[자바스크립트로 구현한 알고리즘] Get the Middle Character 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Get the Middle Character

You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.Examples:Kata.getMiddle("test") should return "es" Kata.getMiddle("testing") should return "t" Kata.getMiddle("middle") should return "dd" Kata.getMiddle("A") should return "A"InputA word (..

2016.09.18 게시됨

[자바스크립트로 구현한 알고리즘] Highest and Lowest 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Highest and Lowest

In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.Example:highAndLow("1 2 3 4 5"); // return "5 1"highAndLow("1 2 -3 4 5"); // return "5 -3"highAndLow("1 9 3 4 -5"); // return "9 -5" Notes:· All numbers are valid Int32, no need to validate them.· There will always be at least one number in the input string. · Output stri..

2016.09.18 게시됨

[자바스크립트로 구현한 알고리즘] Complementary DNA 포스팅 썸네일 이미지

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Complementary DNA

Description: Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms. If you want to know more http://en.wikipedia.org/wiki/DNA In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". You have function with one side of the DNA (string, except for Haskell); you need to..

2016.09.17 게시됨

728x90
반응형