Skip to content

Instantly share code, notes, and snippets.

@sergey12313
Last active April 4, 2018 13:12
Show Gist options
  • Save sergey12313/53fd1eef7b77451dc3479c2745bc3ea5 to your computer and use it in GitHub Desktop.
Save sergey12313/53fd1eef7b77451dc3479c2745bc3ea5 to your computer and use it in GitHub Desktop.

Revisions

  1. sergey12313 revised this gist Apr 4, 2018. 3 changed files with 61 additions and 34 deletions.
    61 changes: 61 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,26 @@
    I Spy

    https://www.codewars.com/kata/555185132c0d4cca3d000197

    function spyOn(func) {
    let callCount = 0;
    let args = [];
    let results = [];
    const result = (...arg) => {
    args.push(...arg)
    const returnValue = func.apply(this, arg);
    callCount += 1;
    results.push(returnValue)
    return returnValue;
    };
    result.callCount = () => callCount;
    result.returned = value => results.includes(value);
    result.wasCalledWith = value => args.includes(value);
    return result;
    }
    ----------------------------------------------------------------------------------------------
    Validate Credit Card Number

    https://www.codewars.com/kata/5418a1dd6d8216e18a0012b2

    function validate(n){
    @@ -15,4 +37,43 @@ function validate(n){
    sum += +currentResult;
    }
    return (sum % 10 == 0)
    }
    ----------------------------------------------------------------------------------------------
    Creating a string for an array of objects from a set of words

    https://www.codewars.com/kata/5877786688976801ad000100

    function wordsToObject(input) {
    const arr = input.split(' ');
    const result = arr.reduce((acc, cur, index, arr) => {
    if(index % 2 === 0) acc +=
    `${(index === 0)?'':', '}{name : \'${cur}\', id : \'${arr[index+1]}'\}`
    return acc;
    },'[');

    return `${result}]`;
    }
    ----------------------------------------------------------------------------------------------
    Find the unique number

    https://www.codewars.com/kata/585d7d5adb20cf33cb000235

    function findUniq(arr) {
    if(arr[0] !== arr[arr.length - 1]) {
    if(arr[0] === arr[1]) {
    return arr[arr.length - 1]
    } else {
    return arr[0]
    }

    }
    let result;
    for(let i = 1; i < arr.length - 1; i += 1 ){
    if(arr[i] !== arr[0]) {
    result = arr[i];
    break;
    }

    }
    return result;
    }
    12 changes: 0 additions & 12 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -1,12 +0,0 @@
    Creating a string for an array of objects from a set of words
    https://www.codewars.com/kata/5877786688976801ad000100
    function wordsToObject(input) {
    const arr = input.split(' ');
    const result = arr.reduce((acc, cur, index, arr) => {
    if(index % 2 === 0) acc +=
    `${(index === 0)?'':', '}{name : \'${cur}\', id : \'${arr[index+1]}'\}`
    return acc;
    },'[');

    return `${result}]`;
    }
    22 changes: 0 additions & 22 deletions gistfile3.txt
    Original file line number Diff line number Diff line change
    @@ -1,22 +0,0 @@
    Find the unique number
    https://www.codewars.com/kata/585d7d5adb20cf33cb000235

    function findUniq(arr) {
    if(arr[0] !== arr[arr.length - 1]) {
    if(arr[0] === arr[1]) {
    return arr[arr.length - 1]
    } else {
    return arr[0]
    }

    }
    let result;
    for(let i = 1; i < arr.length - 1; i += 1 ){
    if(arr[i] !== arr[0]) {
    result = arr[i];
    break;
    }

    }
    return result;
    }
  2. sergey12313 created this gist Apr 4, 2018.
    18 changes: 18 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    Validate Credit Card Number
    https://www.codewars.com/kata/5418a1dd6d8216e18a0012b2

    function validate(n){
    const arr = n.toString().split('');
    let sum = 0;
    for (let i = 0, length = arr.length; i < length; i += 1) {
    const condition = length % 2 === 0 ? i % 2 === 0 : i % 2 !== 0;
    const elem = arr[i];
    let currentResult = elem;
    if (condition) {
    let mult = elem * 2;
    currentResult = mult > 9 ? mult - 9 : mult;
    }
    sum += +currentResult;
    }
    return (sum % 10 == 0)
    }
    12 changes: 12 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    Creating a string for an array of objects from a set of words
    https://www.codewars.com/kata/5877786688976801ad000100
    function wordsToObject(input) {
    const arr = input.split(' ');
    const result = arr.reduce((acc, cur, index, arr) => {
    if(index % 2 === 0) acc +=
    `${(index === 0)?'':', '}{name : \'${cur}\', id : \'${arr[index+1]}'\}`
    return acc;
    },'[');

    return `${result}]`;
    }
    22 changes: 22 additions & 0 deletions gistfile3.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    Find the unique number
    https://www.codewars.com/kata/585d7d5adb20cf33cb000235

    function findUniq(arr) {
    if(arr[0] !== arr[arr.length - 1]) {
    if(arr[0] === arr[1]) {
    return arr[arr.length - 1]
    } else {
    return arr[0]
    }

    }
    let result;
    for(let i = 1; i < arr.length - 1; i += 1 ){
    if(arr[i] !== arr[0]) {
    result = arr[i];
    break;
    }

    }
    return result;
    }