This file contains 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 characters
#!/bin/sh | |
#Check the Drive Space Used by Cached Files | |
du -sh /var/cache/apt/archives | |
#Clean all the log file | |
#for logs in `find /var/log -type f`; do > $logs; done | |
logs=`find /var/log -type f` | |
for i in $logs |
This file contains 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 characters
// [ | |
// [ 1, 2, 3 ], | |
// [ 4, 5, 6 ], | |
// [ 7, 8, 9 ] | |
// ] | |
function sum(matrix) { | |
return matrix.reduce((sum, value, index) => sum + value[index] + value[value.length - index -1], 0); | |
} |
This file contains 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 characters
Write a function that finds the first element that appers an even number of times in an unsorted array. | |
// input: [5,3,5,1,5,1,3] | |
// output: 3 | |
let arr = [5,3,5,1,5,1,3]; | |
let value = ''; | |
for(let i = 0; i < arr.length; i++){ | |
let val = arr[i]; | |
if(arr.filter((v) => v === val).length % 2 == 0){ | |
value = val; |
This file contains 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 characters
// input [1,2,4,2,7,2] | |
//output [1,2,4,2] == 9 | |
[7,2] == 9 | |
const sum = (array) => array.reduce((total, val) => total + val); | |
const arr = [1,2,4,2,7,2]; | |
const arraySum = sum(arr) / 2; | |
let arr1 = [], arr2 = []; | |
for(i =0; i < arr.length; i++) { | |
if(sum([...arr1, arr[i]]) <= arraySum) |
This file contains 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 characters
function digital_root(n) { | |
let values = convertIntToArray(n); | |
let sum = 0; | |
sum = values.reduce(doSum); | |
if((convertIntToArray(n)).length > 1) { | |
return digital_root(sum); | |
} else { | |
return sum; | |
} |
This file contains 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 characters
Example: | |
// a = "xyaabbbccccdefww" | |
// b = "xxxxyyyyabklmopq" | |
// longest(a, b) -> "abcdefklmopqwxy" | |
// a = "abcdefghijklmnopqrstuvwxyz" | |
// longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" | |
function longest(s1, s2) { |
This file contains 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 characters
function spinWords(word){ | |
return (word.split(' ').map(reverseWord)).join(' '); | |
} | |
function reverseWord(word) { | |
if((word.split('')).length > 4) { | |
return (word.split('').reverse()).join(''); | |
} else { | |
return word; | |
} | |
} |
This file contains 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 characters
function findEvenIndex(arr) | |
{ | |
let i; | |
for(i = 0; i < arr.length; i++){ | |
let slic1 = arr.slice(0,i).reduce((num1, num2) => num1 + num2, 0); | |
let slic2 = arr.slice((i + 1), arr.length).reduce((num1, num2) => num1 + num2, 0); | |
if(slic1 == slic2){ | |
return i; | |
} | |
} |
This file contains 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 characters
function isValidWalk(walk) { | |
var dx = 0 | |
var dy = 0 | |
var dt = walk.length | |
for (var i = 0; i < walk.length; i++) { | |
switch (walk[i]) { | |
case 'n': dy--; break | |
case 's': dy++; break | |
case 'w': dx--; break |
This file contains 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 characters
function filter_list(l) { | |
return l.filter(a=>Number.isInteger(a)); | |
} |
NewerOlder