본문 바로가기

js26

Default Import 와 Named Import 의 Import 방식 차이 Next.js 를 새롭게 배우고 있는데 함수를 Import 하다가 뭔가 생긴게 이상하다 싶어서 알게된 Default Import와 Named Import. 그래서 알게된 것을 글로 정리 해보았다.  Default ImportDefault Import는 파일에서 하나의 컴포넌트를 기본으로 내보내고, 이를 가져올 때 사용하는 방식이다. 예를 들어, components/todo.tsx 파일에서 Todo 컴포넌트를 기본으로 내보낼 수 있다. // components/todo.tsxexport default function Todo() { return Todo Component;} 그리고 아래 예시처럼 Todo 컴포넌트를 가져올 수 있다.// app/page.tsximport Todo from "../com.. 2024. 8. 1.
0109. A Needle in the Haystack Can you find the needle in the haystack? Write a function findNeedle() that takes an array full of junk but containing one "needle" After your function finds the needle it should return a message (as a string) that says: "found the needle at position " plus the index it found the needle, so: Example(Input --> Output) ["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"] --> "found th.. 2023. 1. 9.
0108. How many lightsabers do you own? Inspired by the development team at Vooza, write the function that accepts the name of a programmer, and returns the number of lightsabers owned by that person. The only person who owns lightsabers is Zach, by the way. He owns 18, which is an awesome number of lightsabers. Anyone else owns 0. Note: your function should have a default parameter. For example(Input --> Output): "anyone else" --> 0 .. 2023. 1. 9.
0107. Exclamation marks series #4: Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string Description: Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string. For a beginner kata, you can assume that the input data is always a non empty string, no need to verify it. Examples remove("Hi!") === "Hi!" remove("Hi!!!") === "Hi!" remove("!Hi") === "Hi!" remove("!Hi!") === "Hi!" remove("Hi! Hi!") === "Hi Hi!" remove("Hi") === "Hi!" Solution: const remo.. 2023. 1. 7.
0106. Is there a vowel in there? Given an array of numbers, check if any of the numbers are the character codes for lower case vowels (a, e, i, o, u). If they are, change the array value to a string of that vowel. Return the resulting array. Solution: function isVow(a){ for (let index in a) { let vow = String.fromCharCode(a[index]) if (["a", "e", "i", "o", "u"].includes(vow)) { a[index] = vow } } return a } const isVow = a => a.. 2023. 1. 7.
0105. Greet Me Write a method that takes one argument as name and then greets that name, capitalized and ends with an exclamation point. Example: "riley" --> "Hello Riley!" "JACK" --> "Hello Jack!" Solution: var greet = function(name) { modifiedName = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase() return `Hello ${modifiedName}!` }; var greet = function(name) { return 'Hello ' + name[0].toUpperCase(.. 2023. 1. 5.