Last active
          April 4, 2018 13:12 
        
      - 
      
 - 
        
Save sergey12313/53fd1eef7b77451dc3479c2745bc3ea5 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
sergey12313 revised this gist
Apr 4, 2018 . 3 changed files with 61 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,22 +0,0 @@  - 
        
sergey12313 created this gist
Apr 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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}]`; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; }