Coder Social home page Coder Social logo

Comments (19)

shoo7830 avatar shoo7830 commented on May 30, 2024 4

reduce 예시 중 2번째 내용에서 array.reducenumbers.reduce 로 바뀌어야 할듯합니다.

from learnjs.

linkb avatar linkb commented on May 30, 2024 2

심심해서 적어봅니다.

// 10보다 큰 숫자개수

// forEach
function countBiggerThenTen(numbers){
let cnt = 0
numbers.forEach(n => {
cnt += n>10 ? 1 : 0
})
return cnt
}

const count = countBiggerThenTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60])
console.log(count)

// 출력 :
5

// for
function countBiggerThenTen(numbers){
let cnt = 0
for(let i=0;i<numbers.length;i++) {
cnt += numbers[i]>10 ? 1 : 0
}
return cnt
}

const count = countBiggerThenTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60])
console.log(count)
// 출력 :
5

// map
function countBiggerThenTen(numbers){
let cnt = 0;
numbers.map((n) => {
cnt += n > 10 ? 1 : 0
})
return cnt
}

const count = countBiggerThenTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60])
console.log(count)
// 출력 :
5

// filter
function countBiggerThenTen(numbers){
let cnt = 0;
numbers.filter((n) => {
cnt += n > 10 ? 1 : 0
})
return cnt
}

const count = countBiggerThenTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60])
console.log(count)
// 출력 :
5

// reduce
function countBiggerThenTen(numbers){
let cnt = numbers.reduce((res, cval, idx, arr) => {
return res += cval > 10 ? 1 : 0
}, 0)
return cnt
}

const count = countBiggerThenTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60])
console.log(count)
// 출력 :
5

from learnjs.

september-choe avatar september-choe commented on May 30, 2024 1

님 댓글 보고 저도 궁금해져서 찾아봤어요.

https://www.zerocho.com/category/JavaScript/post/5b2b45cf1350f9001b662ba6
console.log는 참조를 로깅하기 때문에, 객체와 같이 내용물이 변할 수 있는 것들은 내용이 실시간으로 바뀝니다.

https://preamtree.tistory.com/115
JavaScript에서는 배열(Array)도 객체(Object)다

질문이 생겨서 질문을 올려봅니다.
console.log에 관한 질문인데요.
push, splice, pop 등, 원래의 배열을 건드리는 내장함수들은
console.log문 밑에서 실행을 했음에도 불구하고, 마치 제일 위에 적은 것처럼
모든 console.log문에 동일한, 이미 내장함수가 실행된 결과가 출력이 되는데,
이 점에 대해서 언급을 해주지 않으셔가지고, 물어봅니다.

이는 여태까지
let a = 1;
console.log(a);
a = 2;
console.log(a);
-> 결과값
1
2
로 나왔던것과는 전혀 다른, 한마디로 절차지향적 느낌이 전혀 없네요.

이 부분에 대해서 설명좀 부탁드려도 될까요?
조금 어렵게 질문한건가 싶어 다시 적어볼게요
const a = [1,2,3,4];
console.log(a)
a.push(5)
console.log(a)
저는 당연히
[1,2,3,4]
[1,2,3,4,5]
이렇게 찍힐 줄 알았는데
둘다 [1,2,3,4,5]로 찍혀서요. 분명 하나의 console.log는 push 밑에 있는데 왜 동일한 결과가 나올까요?

from learnjs.

jnssanaee avatar jnssanaee commented on May 30, 2024 1

오타가 있습니다.

건들이지 => 건드리지

from learnjs.

stdcppgarf avatar stdcppgarf commented on May 30, 2024

덕분에 모던JS 잘 듣고 있습니다^^
chap01-26 강의 영상을 shift-unshift, pop-push 부분과 concat-join 부분으로 나누어 편집하면 나중에 찾아볼때 더욱 좋을 것 같습니다.

from learnjs.

JohnQue avatar JohnQue commented on May 30, 2024

질문이 생겨서 질문을 올려봅니다.
console.log에 관한 질문인데요.
push, splice, pop 등, 원래의 배열을 건드리는 내장함수들은
console.log문 밑에서 실행을 했음에도 불구하고, 마치 제일 위에 적은 것처럼
모든 console.log문에 동일한, 이미 내장함수가 실행된 결과가 출력이 되는데,
이 점에 대해서 언급을 해주지 않으셔가지고, 물어봅니다.

이는 여태까지
let a = 1;
console.log(a);
a = 2;
console.log(a);
-> 결과값
1
2
로 나왔던것과는 전혀 다른, 한마디로 절차지향적 느낌이 전혀 없네요.

이 부분에 대해서 설명좀 부탁드려도 될까요?
조금 어렵게 질문한건가 싶어 다시 적어볼게요
const a = [1,2,3,4];
console.log(a)
a.push(5)
console.log(a)
저는 당연히
[1,2,3,4]
[1,2,3,4,5]
이렇게 찍힐 줄 알았는데
둘다 [1,2,3,4,5]로 찍혀서요. 분명 하나의 console.log는 push 밑에 있는데 왜 동일한 결과가 나올까요?

from learnjs.

pji0219 avatar pji0219 commented on May 30, 2024

강사님 안녕하세요~
강의 잘 듣고 있습니다:)
감사합니다:)

궁금한 것이 있는데 forEach 내장함수의 파라미터로는 화살표 함수에 {}를 써주었는데
다른 내장함수의 파라미터에 들어가는 화살표 함수는 {}가 생략이 되어 있는데 그 이유가 무엇인지 궁금합니다~
그리고 제가 호기심에 forEach문을 제외한 다른 내장함수에 {}를 쓴 화살표 함수를 파라미터로 넣어봤는데 엉뚱한 결과가 나오더라구요 원인이 무엇 일까요?

from learnjs.

pji0219 avatar pji0219 commented on May 30, 2024

근데 여러분 여기서 어떻게 로그아웃 하나요?ㅠㅠ 로그아웃 버튼이 없네요ㅠㅠ

from learnjs.

oshosh avatar oshosh commented on May 30, 2024

function countBiggerThanTen(numbers) {
let reduce_arr = numbers.reduce((prep, current) => {
if (current > 10) prep.push(current);
return prep;
}, []);
return reduce_arr.length;
}

const count = countBiggerThanTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60]);
console.log(count); // 5

export default countBiggerThanTen;

from learnjs.

kdj9878 avatar kdj9878 commented on May 30, 2024

강의 잘 듣고 있습니다.

function countBiggerThanTen(numbers) {
let c = 0;
numbers.filter(v => v > 10).map((value, index) => c++);
return c;
}

from learnjs.

steven-yn avatar steven-yn commented on May 30, 2024
// sol 1
const countBiggerThanTen = (numbers) => {
  const largerThen10 = numbers.filter((nums) => nums > 10);
  return largerThen10.length;
};

const count = countBiggerThanTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60]);
console.log(count); // 5

// sol 2

const countBiggerThanTen = (numbers) => {
  const index = numbers.indexOf(10);
  const largerThen10 = numbers.splice(index, numbers.length - index);
  largerThen10.shift();
  return largerThen10.length;
};

const count = countBiggerThanTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60]);
console.log(count); // 5

from learnjs.

yongjun613 avatar yongjun613 commented on May 30, 2024

function countBiggerThanTen(numbers) {
let num = numbers.reduce((accumulate, current) => {
if(current > 10)
return ++accumulate;
else
return accumulate;
}, 0);

return num;
}

const count = countBiggerThanTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60]);
console.log(count); // 5

export default countBiggerThanTen;

from learnjs.

Jibros avatar Jibros commented on May 30, 2024

22.03.22

from learnjs.

zuzubibi avatar zuzubibi commented on May 30, 2024

22.03.24

from learnjs.

studyToStudy avatar studyToStudy commented on May 30, 2024

22.08.17

from learnjs.

studyToStudy avatar studyToStudy commented on May 30, 2024

function countBiggerThanTen(numbers) {
/* 구현해보세요 */
let count = 0;
numbers.forEach(x => {
if(x > 10){
count++
}
});
return count
}

from learnjs.

sgh055 avatar sgh055 commented on May 30, 2024

function countBiggerThanTen(numbers) {
/* 구현해보세요 */
return numbers.reduce((accumulator, number) => {
if(number > 10) {
return accumulator + 1;
}
return accumulator;
},0);
}

const count = countBiggerThanTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60]);
console.log(count); // 5

export default countBiggerThanTen;

from learnjs.

kimdaeyeobbb avatar kimdaeyeobbb commented on May 30, 2024

제가 구현한 퀴즈 정답입니다

function countBiggerThanTen(numbers) {
    let num = numbers.reduce((acc, cur) => (cur > 10 ? acc += 1 : acc), 0)
    return num
}

const count = countBiggerThanTen([1, 2, 3, 5, 10, 20, 30, 40, 50, 60]);
console.log(count); // 5

from learnjs.

DANU011 avatar DANU011 commented on May 30, 2024

230313

from learnjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.