File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Author: Ferdhika Yudira
2+ // Quadrant detector
3+
4+ var quadrant = function ( x , y ) {
5+ var quadrant = 4 ;
6+
7+ if ( x > 0 && y > 0 ) {
8+ quadrant = 1 ;
9+ } else if ( x < 0 && y > 0 ) {
10+ quadrant = 2 ;
11+ } else if ( x < 0 && y < 0 ) {
12+ quadrant = 3 ;
13+ }
14+
15+ return quadrant ;
16+ }
17+
18+ // test
19+ console . log ( quadrant ( - 5 , 2 ) ) ;
20+ console . log ( quadrant ( 5 , 2 ) ) ;
21+ console . log ( quadrant ( - 5 , - 2 ) ) ;
Original file line number Diff line number Diff line change 1+ // Author: Ferdhika Yudira
2+ // Palindrome
3+
4+ var isPalindrome = function ( text ) {
5+ text = text . split ( '' ) ;
6+ index = 0 ;
7+ palindrom = true ;
8+
9+ pTeks = text . length ;
10+
11+ i = 0 ;
12+ while ( ( i < pTeks / 2 ) && ( palindrom === true ) ) {
13+ if ( text [ index ] == text [ pTeks - 1 ] ) {
14+ index ++ ;
15+ pTeks -- ;
16+ } else {
17+ palindrom = false ;
18+ }
19+
20+ i ++ ;
21+ }
22+
23+ return palindrom ;
24+ }
25+
26+ // test
27+ var cases = "ada apa dengan kakak kakak lari sejak malam ada ada saja" ;
28+
29+ cases . split ( " " ) . map ( function ( res , i ) {
30+ console . log ( res + " : isPalindrom? " + isPalindrome ( res ) ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments