๐Ÿ“
til
  • TIL(Today I Learned)
  • javascript
    • value-number-string-boolean-null-undefined
    • primitive-reference
    • Hoisting
    • Prototypes in Javascript
    • this
    • prototype
    • ์ฝœ๋ฐฑํ•จ์ˆ˜ (Callback function)
    • ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ
    • ์ž๋ฃŒ๊ตฌ์กฐ new keyword
    • closure
    • Promise
    • event-loop
    • array-object
    • ๊ฐ์ฒด
    • Arguments
    • higher order function
    • operators-function-control-flow
    • ๊ฐ์ฒด ์ƒ์„ฑ ํŒจํ„ด 3๊ฐ€์ง€
    • Javascript scopes
    • Functional Programming
    • Design Patterns
    • ๋ฐ์ดํ„ฐ ํƒ€์ž…
    • Object ๊ฐ์ฒด
    • ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ™•์žฅ
    • ์ฐธ์กฐ
    • ํ•จ์ˆ˜
    • ์ƒ์†(Inheritance)
    • this - 'this'๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ '์–ด๋–ป๊ฒŒ' ์‹คํ–‰ํ•˜๋А๋ƒ์— ๋”ฐ๋ฅธ 4๊ฐ€์ง€ this ์ •์˜
    • ์ „์—ญ๊ฐ์ฒด(Global object)
    • ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
    • The 'new' keyword - Object Creation in JavaScript
  • javascript-api
    • Number
      • Number.MAX_VALUE
      • Number.isInteger
      • Number.NEGATIVE_INFINITY
      • Number.isNaN()
      • Number.POSITIVE_INFINITY
      • Number.parseFloat
      • Number.EPSILON
      • number.toExponential
      • Number.MAX_SAFE_INTEGER
      • Number1 - ์ž์—ฐ์ˆ˜, ์ •์ˆ˜, 10์ง„์ˆ˜, 2์ง„์ˆ˜, ๋ถ€๋™์†Œ์ˆ˜์ , ์‹ค์ˆ˜
      • Number.isSafeInteger()
      • Number.MIN_VALUE
      • Number.parseInt
      • Number.NaN
      • Number.isFinite()
      • Number.MIN_SAFE_INTEGER
      • toFixed
    • string.split
    • String.fromCodePoint
    • string.trimEnd
    • string.padStart
    • string.@@iterator
    • String.fromCharCode
    • string.toUpperCase
    • string.codePointAt
    • string.toLowerCase()
    • string.toString
    • string.includes
    • string.replace()
    • string.charAt
    • String.lastIndexOf
    • string.slice
    • string.search
    • string.padEnd
    • string.substring
    • string.length
    • string.trim
    • string.localeCompare
    • String.indexOf
    • string.endsWith
    • string.valueOf
    • String.raw
    • string.matchAll()
    • string.repeat
    • string.match
    • String.prototype
    • string.startsWith
    • string.charCodeAt
    • string.trimStart
    • string.concat
    • string.toLocaleUpperCase()
    • string.toLocaleLowerCase
    • String
  • learn-node
    • debugger
    • Tip
  • schema-design
    • Database Schema Design
    • Database Schema Design
  • react
    • LifeCycle
    • redux
    • Context API
    • ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํด๋ž˜์Šค, ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์กด์žฌํ• ๊นŒ?
    • Hooks๊ณผ useEffect ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ
    • Route
    • async wait ์‚ฌ์šฉํ•˜๊ธฐ
    • Hooks API Reference
    • context
    • npm uninstall ํ•˜๋Š”๋ฒ•
    • test ๋งŒ๋“ค๊ธฐ
  • tip
    • ํด๋ฆฐ์ฝ”๋“œ
    • BxSlider๋กœ ํ…์ŠคํŠธ ํ๋ฅด๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ
  • javascript30
    • Event Capture, Propagation, Bubbling and Once
    • Object and Arrays - Reference VS Copy
  • typescript
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ 2๋ถ€
    • The Basic Cheatsheet
    • TypeScript
    • Type Guards and Differnetiating Types
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ
    • Generics
  • git-from-the-hell
    • git
    • init-status-add-commit-log-stage-repository
    • log-diff
    • ๋จธ์ง€ ํ›„ branch ์‚ญ์ œํ•˜๊ธฐ
    • ์ง€์˜ฅ์—์„œ ์˜จ Git
    • reset-revert
    • develop branch ๋ฅผ pull ํ•˜๊ณ  ์‹ถ์„๋•Œ
  • conference-and-seminar
    • ๋ชจ๋˜ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœํ™˜๊ฒฝ์˜ ์ดํ•ด
  • fire-base
    • Firebase .gitignore
  • vanillacoding
    • Data Structures
    • Sorting Algorithms - part 1
    • Promise
    • class
    • 04.quiz
    • 07.event-loop
    • Design Patterns
    • OOP (Object Oriented Programming)
  • etc
    • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฝ”๋“œ๋ฆฌ๋ทฐ
    • ์Šค์Šค๋กœ ๊ณต๋ถ€ํ•˜๋Š” ๋ฒ•
    • ๋ฐ”๋‹๋ผ์ฝ”๋”ฉ ์ˆ˜๊ฐ• ํ›„๊ธฐ
    • async ๊ณผ์ œ ํ›„๊ธฐ - ๋น„๋™๊ธฐ, ๋™๊ธฐ, ํด๋กœ์ €, ๋ฐฐ์—ด๊ณผ ๊ฐ์ฒด
    • ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ
  • algorithm
    • The Supermarket Queue
    • Find the odd int
    • The Office III - Broken Photocopier
    • Directions Reduction
    • The Office II - Boredom Score
    • Divisible Sum Pairs
    • Codewars ์ด์šฉ์ž ์†”๋ฃจ์…˜ ๋ชจ์Œ
    • Shortest Word
    • find key
    • Two Sum
    • Simple Pig Latin
  • Book
    • the essence of object-orientation
      • ํƒ€์ž…๊ณผ ์ถ”์ƒํ™”
      • ๊ฐ์ฒด ์ง€๋„
      • ์ด์ƒํ•œ ๋‚˜๋ผ์˜ ๊ฐ์ฒด
      • ์ถ”์ƒํ™” ๊ธฐ๋ฒ•
      • 05. ์ฑ…์ž„๊ณผ ๋ฉ”์‹œ์ง€
      • 07.ํ•จ๊ป˜ ๋ชจ์œผ๊ธฐ
      • 04. ์—ญํ• , ์ฑ…์ž„, ํ˜‘๋ ฅ
      • ํ˜‘๋ ฅํ•˜๋Š” ๊ฐ์ฒด๋“ค์˜ ๊ณต๋™์ฒด
  • ecma-script2015
    • Object Literal Upgrades
    • default-parameter-template-literals-arrow-functions
    • spread-operator-rest-param
    • let-const-rest-parameter-spread-operator-destructuring
  • http
    • ์›น ๋ธŒ๋ผ์šฐ์ €์— URL์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ์›น ํŽ˜์ด์ง€๊ฐ€ ๋ณด์—ฌ์งˆ๊นŒ?
  • jest
    • toThrow(error?)
  • data-structures
    • Data Structures
  • express
    • express generator
    • CORS
  • css-flexible-box-layout
    • flex ํ•ด๋ฒ„๋ ธ์ง€ ๋ญ์•ผ
  • git
    • Git
  • mongodb
    • MongoDB
  • markdown
    • use-markdown
  • cmder
    • cmd ๋ช…๋ น์–ด ๋ชจ์Œ
  • debug
    • trackClicksEx function error
  • npm
    • NPM TOKEN ์„ค์ •ํ•˜๊ธฐ
  • storybook
    • Storybook
  • sort
    • Sorting Algorithms - part 1
  • javascript-koans
    • Javascript Koans ์˜ค๋‹ต๋…ธํŠธ
  • rxjs
    • Rx.js
  • dom-elements
    • HTML Element
  • redux-toolkit
    • Redux Toolkit
  • github-actions
    • GitHub Actions
  • redux-middleware
    • redux middleware
  • rest
    • rest
  • css-rendering
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 2/2
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 1/2
  • you-dont-know-js
    • ํƒ€์ž…
  • server
    • # shutdown local server
  • semantic-versioning
    • Semantic Versioning 2.0.0
Powered by GitBook
On this page
  • ๋ฌธ์ œ ์ดํ•ด
  • ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•
  • ์ฝ”๋“œ ๊ตฌํ˜„
  • ๊ฒฐ๊ณผ ๋ถ„์„
  • codewars user's solution

Was this helpful?

  1. algorithm

Shortest Word

PreviousCodewars ์ด์šฉ์ž ์†”๋ฃจ์…˜ ๋ชจ์ŒNextfind key

Last updated 5 years ago

Was this helpful?

๋ฌธ์ œ ์ดํ•ด

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.

๋ฌธ์žฅ์—์„œ ๊ฐ€์žฅ ์งง์€ ๋‹จ์–ด๋ฅผ ์ฐพ์•„๋‚ด์–ด ๋‹จ์–ด์˜ ์ˆ˜๋ฅผ return ํ•œ๋‹ค.

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

  • ๋‹จ์–ด๋ฅผ Array ๋ฉ”์†Œ๋“œ์ธ split๋ฅผ ์ด์šฉํ•ด ๋ฐฐ์—ด์˜ ์›์†Œ๋กœ ๋‹ด๋Š”๋‹ค.

  • for๋ฌธ์„ ์ด์šฉํ•ด ์›์†Œ์˜ ๊ฐ€์žฅ ์งง์€ ๋‹จ์–ด์˜ length๋ฅผ ๋ณ€์ˆ˜์— ๋‹ด๋Š”๋‹ค.

  • length๋ฅผ ๋‹ด์€ ๋ณ€์ˆ˜๋ฅผ return ํ•œ๋‹ค.

์ฝ”๋“œ ๊ตฌํ˜„

function findShort(s){
  var array = s.split(' ');
  var textLength = array[0].length;

  for(var i = 1; i < array.length; i++) {
    if(textLength > array[i].length) {
      textLength = array[i].length;
    }
  }

  return textLength;
}

๊ฒฐ๊ณผ ๋ถ„์„

ํ†ต๊ณผ

codewars user's solution

function findShort(s){
  return Math.min.apply(null, s.split(' ').map(w => w.length));
}
function findShort(s){
    return Math.min(...s.split(" ").map (s => s.length));
}

๋‘๊ฐœ์˜ solution ๋‹ค Math,min์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

์ฐจ์ด๋Š” apply๋ฅผ ์ด์šฉํ•ด ๋ฐฐ์—ด์„ ์—ด๊ฑฐ ํ•˜๊ฑฐ๋‚˜ spread ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

, , , , , (plus 42 more warriors)

Shortest Word Link
sgmaster
Armand
naiqum
3421412
robinab
kalamisu