Skip to content

Instantly share code, notes, and snippets.

@dstyle0210
dstyle0210 / mkdirSync.js
Created November 16, 2016 00:19
[node] 폴더가 없어서 fs.writeFileSync 가 안될때 처리법.(node로 폴더 생성하기)
try{
fs.mkdirSync('생성할폴더명(경로로 지정도 가능)');
}catch(e){
if ( e.code != 'EEXIST' ) throw e; // 존재할경우 패스처리함.
}
@dstyle0210
dstyle0210 / es6_promise.js
Created November 10, 2016 07:53
[es6] promise 기본 사용법
$(function(){
var promise1 = new Promise(function (resolve, reject) {
$.getJSON("ajax경로1",function(result) {
// 해결됨
console.log("첫번째 Promise 완료");
resolve(result);
});
});
@dstyle0210
dstyle0210 / node_request.js
Created November 10, 2016 07:50
[node] node 에서 request을 이용해서, http을 통한 json 가져오기
/**
node 에서 request을 이용해서, http을 통한 json 가져오기.
*/
var fs = require('fs');
var _ = require("underscore");
var request = require("request");
var url = "가져올 JSON 경로"
request({
url: url,
json: true
@dstyle0210
dstyle0210 / codingdojang_study08.js
Created July 18, 2016 00:59
[코딩도장] 사이냅소프트 면접문제
// 코딩도장 공부 : 사이냅소프트 면접문제
// http://codingdojang.com/scode/410
/* 김씨와 이씨는 각각 몇 명 인가요?
"이재영"이란 이름이 몇 번 반복되나요?
중복을 제거한 이름을 출력하세요.
중복을 제거한 이름을 오름차순으로 정렬하여 출력하세요. */
var data = ("이유덕,이재영,권종표,이재영,박민호,강상희,이재영,김지완,최승혁,이성연,박영서,박민호,전경헌,송정환,김재성,이유덕,전경헌").split(",");
var lee = data.filter(function(name){return ((/^이/).test(name))}).length;
var kim = data.filter(function(name){return ((/^김/).test(name))}).length;
var leejy = data.filter(function(name){return ((/^이재영/).test(name))}).length;
@dstyle0210
dstyle0210 / codingdojang_study07.js
Created July 18, 2016 00:38
[코딩도장] 문자열 압축하기
// 코딩도장 공부 : 문자열 압축하기
// http://codingdojang.com/scode/465
var data = "aaabbcccccca";
var str = "";
var num = 1;
var target = "";
data.split("").forEach(function(item){
if(target!=item){
str += (target!="") ? target+""+num : "";
target = item;
@dstyle0210
dstyle0210 / codingdojang_study06.js
Created July 13, 2016 07:21
[코딩도장] Spiral Array
// 코딩도장 공부
// http://codingdojang.com/scode/266
// 임시 데이터 생성.
var col = 8;
var row = 4;
var data = (function(){
var arr = [];
for(i=0;i<row;i++){
arr[i] = new Array(col);
@dstyle0210
dstyle0210 / codingdojang_study05.js
Created July 13, 2016 04:45
[코딩도장] 다음 입사문제 중에서
// 코딩도장 공부
// http://codingdojang.com/scode/408
// 임시 데이터 생성.
var data = (function(){
var arr = [];
for(i=0;i<20;i++){
arr[i] = Math.floor(Math.random()*500);
};
// 데이터 정렬
@dstyle0210
dstyle0210 / codingdojang_study04.js
Created July 12, 2016 09:08
[코딩도장] 게시판 페이징
// 코딩도장 공부
// http://codingdojang.com/scode/406
var m = Math.floor(Math.random()*100); // 총건수
var n = Math.floor(Math.random()*10)+1; // 한페이지에 보여줄 게시물수 (n은 1보다 크거나 같다)
var paging = (0<m) ? Math.floor(m/n) : 0; // 총건수가 0개면, 리턴도 0개.
paging = (paging!=0 && m%n!=0) ? paging + 1 : paging;
console.log(m+","+n+","+paging);
@dstyle0210
dstyle0210 / codingdojang_study03.js
Created July 12, 2016 08:47
[코딩도장] 구글 입사문제 중에서
// 코딩도장 공부
// http://codingdojang.com/scode/393
var samText = "";
for(i=1;i<10000;i++){
samText += i+"";
};
var total = (samText.match(/8/g)).length;
console.log(total);
@dstyle0210
dstyle0210 / codingdojang_study02.js
Last active July 12, 2016 08:36
[코딩도장] 넥슨 입사문제 중에서
// 코딩도장 공부
// http://codingdojang.com/scode/365
var max = 5000;
// 숫자들의 합 구하기.
var total = 0;
(function(){
for(i=0;i<max;i++){
total += i;
};