Blog Day 28: transformFirstAndLast
1. TIL (Today I learned)
transformFirstAndLast
Today afternoon, a discord message from our manager for codestates reminded us that we have a exercise added to our calendar. Algorithm questions for us to let us practice and not forget about past lessons. The manager said that it is vital to do it consistently everyday. A question a day or more if you can actually bear it(I failed on the 2nd question today). To remind myself and also add something to my daily blog, I will add the first question which I succeeded:
The question was to receive a input(array) which consists of different strings as elements. The problem wanted me to not touch the given array and return a new object which consists of the first element of the array as a key and the last element of the array as the key's value.
Result should look like the code below.
let arr = ['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce'];
let output = transformFirstAndLast(arr);
console.log(output); // --> { Queen : 'Beyonce' }
Now the below code is what I came up with.
function transformFirstAndLast(arr) {
const newObj = {}; // new Object is made, a blank one;
if(arr.length === 0){
return newObj; // if arr is a empty array, reutrn newObj which is empty object;
} else {
newObj[arr[0]] = arr[arr.length - 1]; // if arr is not an empty array, add the first value as a key and last value as a value;
}
return newObj;
}
It wasn't too hard but quite challenging and a good reminder.
2. 3 Things to be thankful for
- Thankful for being able to finish a algorithm question.
- Thankful for being safe and healthy.
- Thankful for giving me someone to rely on.
3. Ideas and things to think about.
- As tech-student, we have to think in different ways than that of the normal student. Tech-students have to be eager to fail and try new things. We should not focus on going into one deep thing but we just have to know how to use different tools to come up with something new. A innovative mindset is key and vital. Look at Elon Musk, he doesn't care about other things but always focus on how to be the guy who comes up with something no one else ever did. That is a true tech-student mindset.
Author And Source
이 문제에 관하여(Blog Day 28: transformFirstAndLast), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@inseoparkk/Blog-Day-28-transformFirstAndLast
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
- As tech-student, we have to think in different ways than that of the normal student. Tech-students have to be eager to fail and try new things. We should not focus on going into one deep thing but we just have to know how to use different tools to come up with something new. A innovative mindset is key and vital. Look at Elon Musk, he doesn't care about other things but always focus on how to be the guy who comes up with something no one else ever did. That is a true tech-student mindset.
Author And Source
이 문제에 관하여(Blog Day 28: transformFirstAndLast), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@inseoparkk/Blog-Day-28-transformFirstAndLast저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)