๐ŸงŸโ€โ™€๏ธ์ƒˆ๋กœ ๋ฐœ๊ฒฌํ•œ ๋ฉ”์†Œ๋“œ ์ •๋ฆฌ๐ŸงŸโ€โ™‚๏ธ

9rganizedChaosยท2021๋…„ 2์›” 2์ผ
0
post-thumbnail

String.prototype.match()

  • indexOf๋Š” ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , match๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

  • ํ•ด๋‹น ๊ธ€์ž๊ฐ€ ๋ช‡๋ฒˆ ๋‚˜์˜ค๋Š”์ง€ ํƒ์ƒ‰๊ฐ€๋Šฅ

์ •๊ทœํ‘œํ˜„์‹

์ •๊ทœํ‘œํ˜„์‹์€ ๋ฌธ์ž์—ด์—์„œ ํŠน์ •๋‚ด์šฉ์„ ์ฐพ๊ฑฐ๋‚˜ ๋Œ€์ฒด ๋˜๋Š” ๋ฐœ์ทŒํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•œ๋‹ค.
์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์— ๋งŽ์ด ์“ฐ์ธ๋‹ค.
๋งํฌ

Array.prototype.findIndex()

  • findIndex() ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ๋งŒ์กฑํ•˜๋Š” ๋ฐฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ์— ๋Œ€ํ•œ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์กฑํ•˜๋Š” ์š”์†Œ๊ฐ€ ์—†์œผ๋ฉด -1์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
const array1 = [5, 12, 8, 130, 44];

const isLargeNumber = (element) => element > 13;

console.log(array1.findIndex(isLargeNumber));
// expected output: 3

break์™€ return์˜ ์ฐจ์ด

  • ํ•จ์ˆ˜ ์•ˆ์—์„œ ์ž‘์„ฑ๋œ ๋ฃจํ”„ ์•ˆ์—์„œ break๊ฐ€ ์“ฐ์˜€๋‹ค๋ฉด, break๋ฅผ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ๋ฃจํ”„๋ฅผ ๋น ์ ธ๋‚˜๊ฐ€๊ณ  ํ•จ์ˆ˜ ๋ฐ–์œผ๋กœ๋Š” ๋‚˜๊ฐ€์ง€ ์•Š๋Š”๋‹ค. return์€ ํ•จ์ˆ˜ ์‹คํ–‰์ž์ฒด๋ฅผ ์ข…๋ฃŒํ•˜๊ณ  ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ ๊ณณ์œผ๋กœ ์‹คํ–‰์˜ ํ๋ฆ„์„ ์˜ฎ๊ธด๋‹ค.

Array.prototype.find()

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12

Array.prototype.reverse()

const array1 = ['one', 'two', 'three'];
console.log('array1:', array1);
// expected output: "array1:" Array ["one", "two", "three"]

const reversed = array1.reverse();
console.log('reversed:', reversed);
// expected output: "reversed:" Array ["three", "two", "one"]

// Careful: reverse is destructive -- it changes the original array.
console.log('array1:', array1);
// expected output: "array1:" Array ["three", "two", "one"]

10์ง„๋ฒ• -> n์ง„๋ฒ• ๋ณ€ํ™˜

let value = 10
let binary = value.toString(2) // "1010"

n์ง„๋ฒ• -> 10์ง„๋ฒ• ๋ณ€ํ™˜

Number.parseInt(binary, 2) // 10

String.prototype.charAt()

const sentence = 'The quick brown fox jumps over the lazy dog.';

const index = 4;

console.log(`The character at index ${index} is ${sentence.charAt(index)}`);
// expected output: "The character at index 4 is q"

๊ฐ€์žฅ ์ž‘์€ ์ˆ˜ & ๊ฐ€์žฅ ํฐ ์ˆ˜

Math.min()
Math.max()

๋ฆฌ๋“€์Šค ํ•จ์ˆ˜ ์ธ๋ฑ์Šค ํ™œ์šฉํ•˜๊ธฐ

๋ฌธ์ž์—ด ์ˆซ์ž๋กœ ๋ฐ”๊พธ๊ธฐ

์ˆซ์ž ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ

์ˆซ์ž + ''

์ •์ˆ˜์ธ์ง€ ํŒ๋ณ„

Number.isInteger()

function fits(x, y) {
  if (Number.isInteger(y / x)) {
    return 'Fits!';
  }
  return 'Does NOT fit!';
}

console.log(fits(5, 10));
// expected output: "Fits!"

console.log(fits(5, 11));
// expected output: "Does NOT fit!"

Array.prototype.fill()

  • fill() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ์‹œ์ž‘ ์ธ๋ฑ์Šค๋ถ€ํ„ฐ ๋ ์ธ๋ฑ์Šค์˜ ์ด์ „๊นŒ์ง€ ์ •์ ์ธ ๊ฐ’ ํ•˜๋‚˜๋กœ ์ฑ„์›๋‹ˆ๋‹ค.
const array1 = [1, 2, 3, 4];

// fill with 0 from position 2 until position 4
console.log(array1.fill(0, 2, 4));
// expected output: [1, 2, 0, 0]

// fill with 5 from position 1
console.log(array1.fill(5, 1));
// expected output: [1, 5, 5, 5]

console.log(array1.fill(6));
// expected output: [6, 6, 6, 6]

isNaN()

  • isNaN() ํ•จ์ˆ˜๋Š” ์–ด๋–ค ๊ฐ’์ด NaN์ธ์ง€ ํŒ๋ณ„ํ•ฉ๋‹ˆ๋‹ค. isNaN ํ•จ์ˆ˜๋Š” ๋ช‡๋ช‡ ์ผ๋ฐ˜์ ์ด์ง€ ์•Š์€ ๊ทœ์น™์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฏ€๋กœ, ECMAScript 2015์—์„œ ์ถ”๊ฐ€ํ•œ Number.isNaN()์œผ๋กœ ๋ฐ”๊พธ๋Š” ํŽธ์ด ์ข‹์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
function milliseconds(x) {
  if (isNaN(x)) {
    return 'Not a Number!';
  }
  return x * 1000;
}

console.log(milliseconds('100F'));
// expected output: "Not a Number!"

console.log(milliseconds('0.0314E+2'));
// expected output: 3140

Array.prototype.some()

  • some() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด ์•ˆ์˜ ์–ด๋–ค ์š”์†Œ๋ผ๋„ ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ํ†ต๊ณผํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.
const array = [1, 2, 3, 4, 5];

// checks whether an element is even
const even = (element) => element % 2 === 0;

console.log(array.some(even));
// expected output: true

Array.prototype.every()

  • every() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด ์•ˆ์˜ ๋ชจ๋“  ์š”์†Œ๊ฐ€ ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ํ†ต๊ณผํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.
const isBelowThreshold = (currentValue) => currentValue < 40;

const array1 = [1, 30, 39, 29, 10, 13];

console.log(array1.every(isBelowThreshold));
// expected output: true
profile
๋ถ€์ •ํ™•ํ•œ ์ •๋ณด๋‚˜ ์ž˜๋ชป๋œ ์ •๋ณด๋Š” ๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๋น ๋ฅด๊ฒŒ ์ˆ˜์ •ํ† ๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

0๊ฐœ์˜ ๋Œ“๊ธ€