Code Monkey home page Code Monkey logo

javascript-mission-utils's Introduction

mission-utils

npm tested with jest

Install

with CDN

  1. 스크립트 삽입하기
<script src="https://cdn.jsdelivr.net/npm/@woowacourse/[email protected]/dist/mission-utils.min.js"></script>
<script type="module" src="index.js"></script>
  • index.html에 해당 스크립트 태그를 삽입해주세요.
  • 유틸 라이브러리의 경우 어플리케이션 스크립트 이전에 작성해야 합니다.
  1. 유틸 사용하기
// example
console.log(MissionUtils.Random.pickNumberInList([1, 2, 3]));
  • 스크립트 태그로 삽입된 경우 전역에 할당되어 MissionUtils.[util] 형태로 사용할 수 있습니다.

with npm

  1. 모듈 다운로드
npm i @woowacourse/mission-utils
  1. 모듈 사용하기

ES Modules 방식으로 사용하는 경우

import * as MissionUtils from "@woowacourse/mission-utils";

console.log(MissionUtils.Random.pickNumberInList([1, 2, 3]));

CommonJS 방식으로 사용하는 경우

const MissionUtils = require("@woowacourse/mission-utils");

console.log(MissionUtils.Random.pickNumberInList([1, 2, 3]));

Features

Console

readLine(query, callback)

주어진 질문을 화면에 출력하고, 사용자가 답변을 입력할 때까지 기다린 다음 입력된 답변을 인수로 전달하는 콜백 함수를 호출한다.

Console.readLine('닉네임을 입력해주세요.', (answer) => {
  console.log(`닉네임: ${answer}`);
});

print(message)

주어진 문자열을 콘솔에 출력한다.

Console.print('안녕하세요.');

close()

Console에서 입출력을 제어하기 위해 사용하는 인스턴스를 닫는다.

Console.close();

Random

pickNumberInRange(startInclusive, endInclusive)

숫자 범위를 지정하면 시작 또는 끝 숫자를 포함하여 범위의 숫자를 반환한다.

Random.pickNumberInRange(1, 10); // 1
Random.pickNumberInRange(1, 10); // 10
Random.pickNumberInRange(1, 10); // 4
Random.pickNumberInRange(1, 10); // 5

pickNumberInList(array)

목록에 있는 숫자 중 하나를 반환한다.

Random.pickNumberInList([1, 3, 10]); // 1
Random.pickNumberInList([1, 3, 10]); // 10
Random.pickNumberInList([1, 3, 10]); // 3

pickUniqueNumbersInRange(startInclusive, endInclusive, count)

숫자 범위 내에서 지정된 개수만큼 겹치지 않는 숫자를 반환한다.

Random.pickUniqueNumbersInRange(1, 10, 2); // [1, 2]
Random.pickUniqueNumbersInRange(1, 10, 5); // [1, 10, 7, 8, 5]

shuffle(array)

무작위로 섞인 새 목록을 반환한다.

Random.shuffle([1, 2, 3, 4, 5]); // [2, 4, 1, 3, 5]

Contributors

2SOOY zereight

javascript-mission-utils's People

Contributors

woowapark avatar imakerjun avatar woowahan-pjs avatar

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.