728x90
반응형

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 게시됨

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 게시됨

개발/CSS3

[CSS3] Position : Float

이야기에 앞서 웹 문서가 포함하는 모든 요소의 위치를 잡는 포지셔닝(Positioning)은 사실 웹 디자인의 모든 것이라고 표현 할 수 있습니다. 집을 지을 때도 그에 맞는 Frame을 잘 설계를 해야 원하는 모양의 집을 잘 지을 수 있습니다. 웹사이트도 마찬가지 입니다. 만들고자하는 웹사이트의 Layout을 잘 잡아놔야 그 다음 세부적인 디자인을 쉽게 적용시킬 수 있습니다.하지만 포지셔닝은 꽤 다양한 개념을 이해하고 그것을 복합적으로 잘 사용해야만 원하는 결과를 얻을 수 있을뿐더러, 현재의 기술로 포지셔닝을 하는데 있어서 부딪히는 한계와 버그들에 대한 이해도 필요합니다. 이 글에서는 포지셔닝을 통해 HTML 문법은 물론, 웹 디자인을 위한 기초 골격을 만드는 부분에 대한 개념까지 어느정도 확립할 수 ..

2016.09.19 게시됨

개발/Javascript

자바스크립트 호이스팅(javascript hoisting)

자바스크립트를 공부하다보면 다른 언어와 다른 점이 몇 가지 있습니다. 그 중 호이스팅 (Hoisting)이라 불리는 것이 있는데 이 포스팅은 호이스팅에 대해 알아보는 것에 중점을 두고 있습니다. 호이스팅(hoisting) Hoisting은 hoist라는 단어에서 출발합니다. “끌어 올리는 장치”, “끌어 올리기”라는 뜻입니다. 자바스크립트에서도 호이스팅은 마찬가지로 끌어 올린다는 것이 포인트입니다. 그렇다면 끌어올려지는 것은 무엇일까요? 바로 변수(Variable)입니다. 간단하게 말해서 JavaScript에서의 호이스팅의 의미는 변수 선언문을 끌어올린다는 뜻으로 이해하면 됩니다. 좀 더 이해를 돕기위해 아래의 코드를 준비했습니다. 위의 코드는 호이스팅을 설명하기 위한 간단한 예제입니다. 위 코드를 보시..

2016.09.19 게시됨

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 게시됨

개발/Javascript

[자바스크립트] 배열 요소 중 최대값 최소값 찾기

자바스크립트에는 숫자로 이루어진 배열 내에서 가장 큰 숫자 혹은 가장 작은 숫자를 찾아야 할 경우 for문을 돌리는 단순한 방법 외에 더 간단한 방법이 존재합니다! 먼저 Math 객체를 사용하는 방법이 있습니다. Math 객체에 가장 큰 숫자, 가장 작은 숫자를 구하는 max, min 메서드가 존재하는데 여기에 apply 메서드를 사용하면 숫자로 이루어진 배열을 파라미터로 전달할 수 있게 됩니다. 아래의 예시를 보면 이해하기 쉬울겁니다. 한 가지 조심해야할 부분이 있는데, 배열 내에 비교 불가능한 값이 있다면 결과는 NaN으로 나오게 됨을 주의해야 합니다.

2016.09.18 게시됨

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 게시됨

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 게시됨

Computer science/알고리즘

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

Trolls are attacking your comment section! A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat. Your task is to write a function that takes a string and return a new string with all vowels removed. For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!". 모음만 제거하는 예제다. 정규표현식 /[aeiou]/ gi..

2016.09.17 게시됨

Computer science/알고리즘

[자바스크립트로 구현한 알고리즘] Beginner Series #3 Sum of Numbers

Given two integers, which can be positive and negative, find the sum of all the numbers between including them too and return it. If both numbers are equal return a or b. Note! a and b are not ordered! Example: GetSum(1, 0) == 1 // 1 + 0 = 1 GetSum(1, 2) == 3 // 1 + 2 = 3 GetSum(0, 1) == 1 // 0 + 1 = 1 GetSum(1, 1) == 1 // 1 Since both are same GetSum(-1, 0) == -1 // -1 + 0 = -1 GetSum(-1, 2) ==..

2016.09.17 게시됨

Computer science/알고리즘

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

Create a function with two arguments that will return a list of length (n) with multiples of (x). Assume both the given number and the number of times to count will be positive numbers greater than 0.Return the results as an array (or list in Python, Haskell or Elixir). Examples: countBy(1,10) === [1,2,3,4,5,6,7,8,9,10] countBy(2,5) === [2,4,6,8,10] 이런 방법으로 첫 코딩을 작성했다. 좀 더 보기 좋은 코드로는 이렇게 작성도 가능하다.

2016.09.12 게시됨

728x90
반응형